🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: problema con ejemplo servidor

#8692
From: Lepton
Date: Thu, 17 Oct 2002 07:11
32 lines
1955 bytes
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.
Technical Details
Message-ID: <Pine.LNX.4.44.0210170908570.582-100000@lorien.local>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!opentransit.net!fu-berlin.de!uni-berlin.de!b3512.pppool.DE!not-for-mail
References: <aoksa0$8q$1@reader2.wnet>

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-17 04:02:00 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!opentransit.net!fu-berlin.de!uni-berlin.de!b3512.pppool.DE!not-for-mail
From: Lepton <reinob@jazzfree.com>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: problema con ejemplo servidor
Date: Thu, 17 Oct 2002 09:11:25 +0200
Lines: 34
Message-ID: <Pine.LNX.4.44.0210170908570.582-100000@lorien.local>
References: <aoksa0$8q$1@reader2.wnet>
NNTP-Posting-Host: b3512.pppool.de (213.7.53.18)
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=iso-8859-15
Content-Transfer-Encoding: 8BIT
X-Trace: fu-berlin.de 1034852457 24785275 213.7.53.18 (16 [130846])
X-Orig-Path: localhost!reinob
In-Reply-To: <aoksa0$8q$1@reader2.wnet>