Jump to content

  • Log In with Google      Sign In   
  • Create Account


How can enet listening more than 1 port at same time?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 hsine   Members   -  Reputation: 112

Like
0Likes
Like

Posted 10 January 2013 - 01:27 PM

in my project requires to listening about 3 port at same time for difference busniess , but for enet demo code:

once i established a server by

ENetHost* create server(int port){
ENetAddress* addr;
addr->host=.....
addr->port=port;

server=p2udp_host_create(&serv_addr,MAX_CLIENT_LINKS,MAX_CHANNEL_SET,0,0);

。。。。

return server;
}

than i call this function 3 times so i got about 3 server instance with 3 different ports, but only 1 port can handle events which was first made.

 

so the question is how can i handle the message events for all of 3 ports because event handling  procedure is in located a while loop just like:

 

 

 

service_event_handle(ENetHost* server)
{
  ENETEVENET event;
  while(1){
    switch(.....){
    }
 }

}

when i pass the params server1 create by , it just traped in loop without ending conditions 

 

i wonder how can i  jump the loop do handle evnets for another 2 port

 

,



Sponsor:

#2 KulSeran   Members   -  Reputation: 2222

Like
0Likes
Like

Posted 11 January 2013 - 12:30 AM

You need to re-structure your code a bit?  You need to store all your servers in a container, and just loop over all of them each time instead of letting any one server create the infinite loop.

while (!servers.empty()) {

  for ( std::vector<ENetHost *>::iterator server = servers.begin(); server != servers.end(); ++server) {

    ENETEVENT event;

    if(enet_host_service (client, & event, 3000) > 0)  {
      switch (event.type)
    } else {

      // flag server for disconnect

    }

  }

  // loop again, removing dead servers

}


#3 BeerNutts   Crossbones+   -  Reputation: 2702

Like
0Likes
Like

Posted 11 January 2013 - 02:09 PM

For generic sockets, you create the sockets you need to listen on and bind to the ports you need, then add those sockets to a file descriptor and call select() with that FD.  It will handle everything for you.


My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS