Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How can I listen on more than one port at a time?

Answer Posted / chaitanya

The best way to do this is with the select() call. This tells the kernel to let you know when a socket is available for use. You can have one process do i/o with multiple sockets with this call. If you want to wait for a connect on sockets 4, 6 and 10 you might execute the following code snippet:

fd_set socklist;

FD_ZERO(&socklist); /* Always clear the structure first. */

FD_SET(4, &socklist);

FD_SET(6, &socklist);

FD_SET(10, &socklist);

if (select(11, NULL, &socklist, NULL, NULL) < 0)

perror("select");

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I tell when a socket is closed on the other end?

1292


What is active unix domain sockets?

852


What is a sae socket?

872


What is difference between socket () and serversocket () class?

816


Can multiple sockets use the same port?

817


How can I write a multi-homed server?

1594


How does a socket work?

820


How do I use TCP_NODELAY?

1496


How many socket connections can a server handle?

806


Is there any advantage to handling the signal, rather than just ignoring it and checking for the EPIPE error? Are there any useful parameters passed to the signal catching function?

1361


Are unix sockets faster than tcp?

803


What pieces of information make up a socket?

901


What's the difference between a socket and a port?

794


Where is the socket located?

842


What is a socket file?

834