2
#include <emscripten.h>
9
static int counter = 0;
15
emscripten_cancel_main_loop();
20
if (enet_host_service (host, & event, 0) == 0) return;
23
case ENET_EVENT_TYPE_CONNECT:
24
printf ("Connection succeeded!\n");
27
case ENET_EVENT_TYPE_RECEIVE:
28
printf ("A packet of length %u containing %s was received from %s on channel %u.\n",
29
event.packet -> dataLength,
34
int result = strcmp("packetfoo", event.packet->data);
37
/* Clean up the packet now that we're done using it. */
38
enet_packet_destroy (event.packet);
40
case ENET_EVENT_TYPE_DISCONNECT:
41
printf ("%s disconected.\n", event.peer -> data);
42
/* Reset the peer's client information. */
43
event.peer -> data = NULL;
44
enet_host_destroy(host);
47
printf("whaaa? %d\n", event.type);
51
int main (int argc, char ** argv)
53
if (enet_initialize () != 0)
55
fprintf (stderr, "An error occurred while initializing ENet.\n");
58
atexit (enet_deinitialize);
60
printf("creating host\n");
62
host = enet_host_create (NULL /* create a client host */,
63
1 /* only allow 1 outgoing connection */,
64
2 /* allow up 2 channels to be used, 0 and 1 */,
65
57600 / 8 /* 56K modem with 56 Kbps downstream bandwidth */,
66
14400 / 8 /* 56K modem with 14 Kbps upstream bandwidth */);
70
"An error occurred while trying to create an ENet client host.\n");
75
enet_address_set_host (& address, "localhost");
82
printf("connecting to server...\n");
84
ENetPeer *peer = enet_host_connect (host, & address, 2, 0);
89
"No available peers for initiating an ENet connection.\n");
94
emscripten_run_script("console.log('adding iframe');"
95
"var iframe = document.createElement('iframe');"
96
"iframe.src = 'server.html';"
97
"iframe.width = '100%';"
98
"iframe.height = '33%';"
99
"document.body.appendChild(iframe);"
100
"console.log('added.');");
103
emscripten_set_main_loop(main_loop, 3, 1);