Last active
December 20, 2015 00:59
-
-
Save Ericson2314/6045333 to your computer and use it in GitHub Desktop.
Using this dummy ENet client basically ripped from the tutorial to try to connect to pysnip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdbool.h> | |
#include <enet/enet.h> | |
ENetAddress address; | |
ENetEvent event; | |
ENetPeer* peer; | |
int main (int argc, char* argv[]) | |
{ | |
ENetHost* client = enet_host_create | |
( | |
NULL, // create a client host | |
1, // only allow 1 outgoing connection | |
2, // allow up 2 channels to be used, 0 and 1 | |
0, // MOAR BANDSWITH DOWN | |
0 // MOAR BANDSWITH UP | |
); | |
if (client == NULL) | |
{ | |
fprintf | |
( | |
stderr, | |
"An error occurred while trying to create an ENet client host.\n" | |
); | |
exit (EXIT_FAILURE); | |
} | |
// use range coder for client | |
enet_host_compress_with_range_coder(client); | |
// create address to server | |
enet_address_set_host (& address, "localhost"); | |
address.port = 32887; | |
// Initiate the connection | |
peer = enet_host_connect | |
( | |
client, // source host | |
& address, // dest adddr | |
1, // num Channels | |
3 // magic datum | |
); | |
if (peer == NULL) | |
{ | |
fprintf | |
( | |
stderr, | |
"No available peers for initiating an ENet connection.\n" | |
); | |
exit (EXIT_FAILURE); | |
} | |
// Wait up to 5 seconds for the connection attempt to succeed. | |
while (true) { | |
int temp = enet_host_service | |
( | |
client, // what host to service | |
& event, // where to put event | |
5000 // wait 3/4 second | |
); | |
if (temp < 0) puts("error"); | |
else if (temp == 0) puts("no packet"); | |
else if (temp > 0) | |
{ | |
switch (event.type) | |
{ | |
case ENET_EVENT_TYPE_CONNECT: | |
puts ("got connect"); | |
break; | |
case ENET_EVENT_TYPE_RECEIVE: | |
puts ("got receive"); | |
break; | |
case ENET_EVENT_TYPE_NONE: | |
puts ("got none"); | |
break; | |
case ENET_EVENT_TYPE_DISCONNECT: | |
puts ("got disconnect"); | |
return 0; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment