🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #8715

Re: problema con ejemplo servidor

#8715
From: Antonio
Date: Sat, 19 Oct 2002 11:45
37 lines
2147 bytes
Lepton wrote:

> 
> On Thu, 17 Oct 2002, Antonio wrote:
> 
> #     if( newfd = accept(sockfd,(struct sockaddr *)&clie_addr,
> #     &sin_size)==-1)
> 
> Cambialo por
> 
>      if((newfd = accept(...)) == -1)
> 
> ya que estas diciendo: newfd = (accept() == -1), que es falso, ya que
> accept devuelve un socket > -1, y -1 != -1, asi que newfd = 0
> 
> #             if ((numbytes=recv(newfd, buf, MAX,0)) == -1)
> #             {
> #                 perror("recv");
> #                 exit(1);
> #             }
> #                         /* Visualizamos lo recibido */
> 
> a�ade: buf[numbytes] = '\0', si vas a usar lo que recibes como un
> string, ya que el recv() no a�ade el nulo automaticamente, y el
> printf() lo requiere..
> 
> #             printf("Recivido: %s\n",buf);
> #             close(newfd);
> #             exit(0);
> 
> te aconsejo que justo despues del fork(), en el hijo cierres
> el socket del padre (sockfd), de la misma forma que en el
> padre cierras el socket del hijo.
> 
> Lepton.
Muchisimas gracias por tus consejos, funciono a la perfeccion.
Muchas gracias
Technical Details
Message-ID: <aorg73$fhf$1@reader2.wnet>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!syros.belnet.be!news.belnet.be!opentransit.net!newsfeed.comtenidos.com!newsfeeder.wanadoo.es!not-for-mail
References: <aoksa0$8q$1@reader2.wnet> <Pine.LNX.4.44.0210170908570.582-100000@lorien.local>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,b456828f70148f55
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2002-10-19 04:42:59 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!syros.belnet.be!news.belnet.be!opentransit.net!newsfeed.comtenidos.com!newsfeeder.wanadoo.es!not-for-mail
From: Antonio <aperlu@obelix.umh.es>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: problema con ejemplo servidor
Date: Sat, 19 Oct 2002 13:45:06 +0200
Organization: Wanadoo
Lines: 37
Message-ID: <aorg73$fhf$1@reader2.wnet>
References: <aoksa0$8q$1@reader2.wnet> <Pine.LNX.4.44.0210170908570.582-100000@lorien.local>
NNTP-Posting-Host: 62-36-188-192.dialup.uni2.es
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8Bit
X-Trace: reader2.wnet 1035027494 15919 62.36.188.192 (19 Oct 2002 11:38:14 GMT)
X-Complaints-To: usenet@wanadoo.es
NNTP-Posting-Date: Sat, 19 Oct 2002 11:38:14 +0000 (UTC)
User-Agent: KNode/0.6.1