Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Oct 2002 12:57:24 +0300 (EEST)
From:      Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
To:        Vinod <geekvinod@yahoo.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: help with socket programming
Message-ID:  <200210240957.g9O9vO02002049@pm514-9.comsys.ntu-kpi.kiev.ua>
In-Reply-To: <20021023224447.33671.qmail@web21108.mail.yahoo.com.lucky.freebsd.questions>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 23 Oct 2002 22:45:06 +0000 (UTC) in lucky.freebsd.questions, Vinod wrote:
> i need a socket descriptor handle to process all my
> clients which fork out.but the handle i was using
> new_fd(see below) turned out to be the same for all.
> 
> listen(..,..)
> for(;;)
> {
> int new_fd=accept(sockfd,....,...);
> ...
> ....
> }
> Shouldnt the new_fd be distinct everytime a new client
> connects?

I don't clearly understand your question, especially if you
read Stevens books, but I'll try to answer.

new_fd variable is just overwritten each time accept() returns a new
socket descriptor for a new connection. If you need to keep connections
with all clients at "the same time" in a single server, so, you need to
save each new_fd descriptor in an array, for example.

If you fork() a new process for handling a new connection, then you need
to close() new_fd descriptor in the server and use new_fd descriptor in
the forked process.

In any way, it is better to ask such questions in comp.unix.programmer
news group.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200210240957.g9O9vO02002049>