From owner-freebsd-questions Thu Oct 24 2:57:41 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5792337B401 for ; Thu, 24 Oct 2002 02:57:40 -0700 (PDT) Received: from relay1.ntu-kpi.kiev.ua (www.ntu-kpi.kiev.ua [212.111.192.161]) by mx1.FreeBSD.org (Postfix) with ESMTP id A009E43E6A for ; Thu, 24 Oct 2002 02:57:38 -0700 (PDT) (envelope-from simon@comsys.ntu-kpi.kiev.ua) Received: from comsys.ntu-kpi.kiev.ua (eth0.comsys.ntu-kpi.kiev.ua [10.0.1.184]) by relay1.ntu-kpi.kiev.ua (Postfix) with ESMTP id 8F89619BCE; Thu, 24 Oct 2002 12:57:35 +0300 (EEST) Received: from pm514-9.comsys.ntu-kpi.kiev.ua (pm514-9.comsys.ntu-kpi.kiev.ua [10.18.54.109]) by comsys.ntu-kpi.kiev.ua (8.11.6/8.11.6) with ESMTP id g9OA13839846; Thu, 24 Oct 2002 13:01:03 +0300 (EEST) Received: from pm514-9.comsys.ntu-kpi.kiev.ua (localhost [127.0.0.1]) by pm514-9.comsys.ntu-kpi.kiev.ua (8.12.6/8.12.6) with ESMTP id g9O9vZi7002050; Thu, 24 Oct 2002 12:57:35 +0300 (EEST) (envelope-from simon@pm514-9.comsys.ntu-kpi.kiev.ua) Received: (from simon@localhost) by pm514-9.comsys.ntu-kpi.kiev.ua (8.12.6/8.12.6/Submit) id g9O9vO02002049; Thu, 24 Oct 2002 12:57:24 +0300 (EEST) Date: Thu, 24 Oct 2002 12:57:24 +0300 (EEST) Message-Id: <200210240957.g9O9vO02002049@pm514-9.comsys.ntu-kpi.kiev.ua> From: Andrey Simonenko To: Vinod Cc: freebsd-questions@freebsd.org Subject: Re: help with socket programming In-Reply-To: <20021023224447.33671.qmail@web21108.mail.yahoo.com.lucky.freebsd.questions> X-Newsgroups: lucky.freebsd.questions User-Agent: tin/1.5.12-20020427 ("Sugar") (UNIX) (FreeBSD/4.7-STABLE (i386)) Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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