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 |
How does a socket work?
What is active unix domain sockets?
What pieces of information make up a socket?
After the chroot(), calls to socket() are failing. Why?
How come select says there is data, but read returns zero?
Is tcp or unix socket faster?
What is a deep well socket?
What is a socket api?
What exactly does SO_LINGER do?
What are raw sockets?
How do I get my server to find out the clients address / host- name?
What is the function of socket?