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

What does af mean in sockets?

894


Why do we need sockets?

779


What is difference between socket and websocket?

857


How to find other end of unix socket connection?

850


What is a sae socket?

887


What's better 6pt or 12pt sockets?

787


What is a socket address?

879


system choose one for me on the connect() call? Should I bind() a port number in my client program, or let the?

1577


What's the difference between impact sockets and regular sockets?

808


What is sae socket?

787


Why does it take so long to detect that the peer died?

1468


How can I write a multi-homed server?

1608


Can a socket have multiple ports?

828


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

1309


What are the types of sockets?

890