I having difficulties in understanding how select() function in socket programming work.... I'm trying to create my own peer-to-peer chat or file transfer program by using the select() function.... Therefore does anyone had any tutorial or source code that related to either one of the program, which I'm trying to create?
My problem is how to get the "write" in select() function working?
Let say:
//server.c, which is the server side source code
........
select(highsocket+1, NULL, &writeset, NULL, (timeval*)0);
............
if (FD_ISSET(socket,&writeset))
{
printf("Server is writing.......\n");
}
.............
and now, how do I get the server side to print the word "Server is writing......." ? I hope you guy understand what I mean.......
btw, I'm using NetBDS and using C programming....... hoping someone can help me out
I've attached a hasty, single process server (without any signal handling) example that works on my FreeBSD 6.0 host. Hopefully it will be of assistance. I'd suggest running indent against it. There are also very good arguments for not using select in favor of pselect. Also for high capacity servers maybe kqueue would be better.
My 'liedentd' is a simple select(2)-based server program that is a good example of how to write a high-performance select loop. It is available in the FreeBSD ports system, under security/liedentd, or you can fetch the source from: