Re: creating server socket program to handle multiple client at same time
From: grid (prohit99_at_gmail.com)
Date: 03/15/05
- Next message: Andrei Voropaev: "Re: flock vs socket"
- Previous message: Gianni Mariani: "Re: Makefile Variable <- Program Output?"
- In reply to: kernel.lover: "creating server socket program to handle multiple client at same time"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 15 Mar 2005 11:48:51 +0530
> If yes then when to use then select call(i.e. FD_SET,FD_CLR,FD_SET)?
> if no then select is only thing to have server socket program on one
> pc and other clients on many pcs to have communication with server?
After a connection is received, accept returns a socket file descriptor
which we use for communicating with the client.So here instead of
forking a child you can have a select call and pass this descriptor to
select to tell you when there is activity(read/write) on the socket and
do the communications.
Again,if have a single process handling both accepting connections and
doing I/O , you would also have to pass the socket file descriptor on
which accept is waiting, to select's pool of desciptors.This will help
us to serve clients and also accpet connections at the same time.
> I want to have communication environment with many clients and one
> server serving all at same time.
The design which you have incorporated in your program can also be used
to service multiple clients.You will have to change your program to wait
in a loop for new connections and then fork a child for each new
connection,and then child processess take care of the communication.You
can have you design like :
while loop
accept connection
fork a child
child :
close listening socket
read/write for/to communication socket
close socket
Parent :
close comunication socket
HTH
- Next message: Andrei Voropaev: "Re: flock vs socket"
- Previous message: Gianni Mariani: "Re: Makefile Variable <- Program Output?"
- In reply to: kernel.lover: "creating server socket program to handle multiple client at same time"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|