[ENet-discuss] A little help needed :)
Alexaroth
alex_prislopeanu at yahoo.com
Tue Feb 22 11:42:02 PST 2011
Hey!
Hope this is the right place to put this question...
I just want some little guidance on a small hobby game I am making atm...
Well first off I want to know if I am doing it right :)
Example: I have some test programs: client.exe and server.exe
I was quite clueless on how to make for ex: send a message from client to server and display on server...
I played around a bit and managed to make it work...
I did it like this (and here is where I want to know if I did it well and got things right)
Client.exe:
client = enet_host_create (....) //I create the client
enet_address_set_host (& address, "xx.xx.xx.xx.xx");
address.port = 1234;
peer = enet_host_connect (client, & address, 2, 0); //connect
if (enet_host_service (client, & event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT) {cout>>bla bla} //if connected display a message
and now small confusion:
while (enet_host_service (client, & event, 100) > 0)
{ switch (event.type)
{
case A
case B etc...
I kinda know what this does... I think I must call enet_host_service("what the current exe is(client or server)", & event,100) just to make the transfer between client and server ?
I mean without having this code in the client too, sending is not possible so I guess I must have it anyway.
moving on,
ENetPacket * packet = enet_packet_create (bla bla,strlen (bla bla) + 1, ENET_PACKET_FLAG_RELIABLE); //make packet
enet_peer_send (peer, 0, packet); //send it
call enet_host_service again so that the transfer is made.
And the Server.exe is:
enet_address_set_host (& address, "xx.xxx.xx.xx"); //set address of host
address.port = 1234;
server = enet_host_create (& address ,32,2,0,0); //create server
for(;;)
{update(); Sleep(10);}
where update() contains the whole:
"while (enet_host_service (client, & event, 100) > 0)
{ switch (event.type)
{
case A
case B etc..."
thing... So I make it listen for the client...
Anyway just wanted to know if this is the right principle for this library.
And also a small problem... given these 2 programs, when it should write the IP that connected to the client, it shows up numbers like "A new client connected from 15157e56:61514" where the last part after the : is the port, which I guess is displayed correctly... but the IP is not. What could be the problem ? The case ENET_EVENT_TYPE_CONNECT: is like in the tutorial.
Thanks for your attention,
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20110222/38d32bdb/attachment.html>
More information about the ENet-discuss
mailing list