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?



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

Answer / 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

More Unix Socket Programming Interview Questions

Explain the TIME_WAIT state.

1 Answers  


What pieces of information make up a socket?

0 Answers  


What is the difference between SO_REUSEADDR and SO_REUSEPORT?

0 Answers  


Can multiple sockets use the same port?

0 Answers  


What is the difference between close() and shutdown()?

1 Answers  


Why does connect() succeed even before my server did an accept()?

1 Answers  


How can I write a multi-homed server?

0 Answers  


How do I convert a string into an internet address?

0 Answers  


How should I choose a port number for my server?

1 Answers  


How do I properly close a socket?

1 Answers  


What is the difference between connected and unconnected sockets?

1 Answers  


How can I bind() to a port number < 1024?

1 Answers  


Categories