Prev: AIX iconv question
Next: A couple of sed questions
From: pavunkumar on 5 Oct 2009 00:19 Dear Sir, I have a doubt in socket regarding fork concept . The things is that in server side for handling multiple client I am using fork. after forking I am response to client in child process. and then I am waiting for new client connection in parent process. my doubt is how the server differentiate client request . while having the different connection . Thanks
From: Barry Margolin on 5 Oct 2009 03:22 In article <074557ee-5edd-40d4-8ae3-fa24dc144841(a)r24g2000prf.googlegroups.com>, pavunkumar <pavun.it(a)gmail.com> wrote: > Dear Sir, > > I have a doubt in socket regarding fork concept . The things is that > in server side for handling multiple client I am using fork. after > forking I am response to client in child process. and then I am > waiting for new client connection in parent process. my doubt is > how the server differentiate client request . while having the > different connection . Each client has a different remote address and/or remote port. If you're using TCP, the socket returned by accept() refers to that client connection. If you're using UDP, you need to use recvfrom() to get the remote address and port of each packet, and dispatch it to the appropriate child process for that client. -- Barry Margolin, barmar(a)alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group ***
From: pavunkumar on 5 Oct 2009 03:45 On Oct 5, 9:19 am, pavunkumar <pavun...(a)gmail.com> wrote: > Dear Sir, > > I have a doubt in socket regarding fork concept . The things is that > in server side for handling multiple client I am using fork. after > forking I am response to client in child process. and then I am > waiting for new client connection in parent process. my doubt is > how the server differentiate client request . while having the > different connection . > > Thanks Dear Sir, Whatever you said that thing I understand . My doubt is that each client will send the request to the server . For example Now the server having two client connection and waiting for next client. This time a connected client sending message to server , Now server is having two process to response each connected client . How the server is doing the differentiate while getting request . is this using header information to differentiate ? . This is what my doubt . Thanks
From: Richard C. Giles on 5 Oct 2009 05:03 On Oct 5, 3:45 am, pavunkumar <pavun...(a)gmail.com> wrote: > On Oct 5, 9:19 am, pavunkumar <pavun...(a)gmail.com> wrote: > > > Dear Sir, > > > I have a doubt in socket regarding fork concept . The things is that > > in server side for handling multiple client I am using fork. after > > forking I am response to client in child process. and then I am > > waiting for new client connection in parent process. my doubt is > > how the server differentiate client request . while having the > > different connection . > > > Thanks > > Dear Sir, > > Whatever you said that thing I understand . My doubt is > that each client will send the request to the server . For example > Now the server having two client connection and waiting for next > client. This time a connected client sending message to server , Now > server is having two process to response each connected client . How > the server is doing the differentiate while getting request . is this > using header information to differentiate ? . This is what my > doubt . > > Thanks After retrieving the address about the client side in the parent process, if desired, the parent process should close the socket to the client. In this way, only the child process will be able to receive messages from the client.
From: Barry Margolin on 5 Oct 2009 17:17
In article <8a8a0064-3a6d-4c35-856d-1bc408223cb0(a)y28g2000prd.googlegroups.com>, pavunkumar <pavun.it(a)gmail.com> wrote: > On Oct 5, 9:19 am, pavunkumar <pavun...(a)gmail.com> wrote: > > Dear Sir, > > > > I have a doubt in socket regarding fork concept . The things is that > > in server side for handling multiple client I am using fork. after > > forking I am response to client in child process. and then I am > > waiting for new client connection in parent process. my doubt is > > how the server differentiate client request . while having the > > different connection . > > > > Thanks > > Dear Sir, > > Whatever you said that thing I understand . My doubt is > that each client will send the request to the server . For example > Now the server having two client connection and waiting for next > client. This time a connected client sending message to server , Now > server is having two process to response each connected client . How > the server is doing the differentiate while getting request . is this > using header information to differentiate ? . This is what my > doubt . The parent process should be in a loop just calling accept() to get new connections on the original listening socket. The child processes should just be calling read() and write() on the connected socket that was returned by accept(). This is a different socket from the original listening socket. The OS differentiates them automatically for you. -- Barry Margolin, barmar(a)alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group *** |