Is there an alternate to while(1) loop in the TCP server ?
Hi Folks,
I have a TCP server ( I named it ikev2_socket_server ) on Linux FC6, kernel 2.6.18. It servers the clients on the Widows machine. This server waits in a while(1){} loop to clients to connect to it. Is there a way I can make this server wait for the client without waiting in the while(1){} loop?
Well the reason I am asking is:
I am trying to make this Server a service much like a dchpd service so that I can start/stop/check status of it. I have created a script ( named it segwd ) much like a /etc/init.d/dhcpd script and kept it in /etc/init.d directory. This script has the functionality to Start, Stop , Status and restart the server.
In the Start case, I m using the daemon command to make this tcp server a daemon. The syntax is
daemon ikev2_socket_server. Now the problem is :
As I do service segwd start, the script does not return. The reason i know is the while(1){} loop in th TCP server which waits for the clients to connect and itself does not return. Is there a way I can make my server wait for clients to connect without using the while(1){} loop?
Regards,
Rajat
|