Article View: news.software.nntp
Article #56235Re: How recv() determines the receiving is finished?
From: Joshua
Date: Sun, 27 Jan 2002 19:25
Date: Sun, 27 Jan 2002 19:25
49 lines
3328 bytes
3328 bytes
Thank you,Russ. In fact, I knew what happens when the remote side closes the connection. I only don't know when the input stream is ending. The News client and Server may run require-respond many times in every single socket session.The client send require command such as "mode reader",and waits the server's respond. Here,client uses recv() to get the responding data. The session will keep open, so client can not determine the ending of the responding data by estimating "return 0".Before the session is closed by any side,the recv() will generally not return 0. There must be other way for this. Thanks for your recommanding on the reference book. This time I am writing a little test tool for News Server,maybe these sort of books are too heavy for me,at least now. I want to make it work firstly.blocked by only this little question.Could you give me more detail about that? Some pieces of sample codes are will be the best. "Russ Allbery" <rra@stanford.edu> wrote in message news:yly9iju1i5.fsf@windlord.stanford.edu... > Joshua <JoshuaIIII@hotmail.com> writes: > > > I think if input stream has any data,recv() will get some of them and > > return the size into received_len.But if the input stream is > > empty,recv() will block there untill new inputing data is found. So,the > > do/while maybe never has a chance to exit,unless some socket error > > issues. > > > And now,I am still not sure how to determine to end the receiving when I > > use recv() to receive data from input stream. > > When the remote side closes the connection, read() on that socket (and the > same for recv() if you're using it like read(), which you are here) will > return 0. That's how you know the other side closed the connection. > > I highly recommend a good book on Unix network programming, since quite a > lot of this isn't entirely obvious and can be difficult to learn piecemeal > from manual pages. I'm surprised that whatever book you got that code > from didn't explain it. > > _Unix Network Programming, Volume One_ by W. Richard Stevens is the most > frequently cited book from which to learn these sorts of things; I highly > recommend it. (Volume one is network sockets and volume two is IPC.)
Technical Details
Message-ID:
<a31khk$895$1@mail.cn99.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.bentium.com!news.cn99.com!not-for-mailReferences:
<a30rss$f0j$1@mail.cn99.com> <yly9iju1i5.fsf@windlord.stanford.edu>Show Full Headers
Complete Article Headers
Message-ID: <a31khk$895$1@mail.cn99.com> Subject: Re: How recv() determines the receiving is finished? Date: Mon, 28 Jan 2002 03:25:45 +0800 From: "Joshua" <JoshuaIIII@hotmail.com> References: <a30rss$f0j$1@mail.cn99.com> <yly9iju1i5.fsf@windlord.stanford.edu> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.bentium.com!news.cn99.com!not-for-mail Newsgroups: news.software.nntp Organization: Bentium Ltd. (CN99) Lines: 48 NNTP-Posting-Host: 61.156.66.54 X-Trace: mail.cn99.com 1012159861 8485 61.156.66.54 (27 Jan 2002 19:31:01 GMT) X-Complaints-To: usenet@news.cn99.com NNTP-Posting-Date: Sun, 27 Jan 2002 19:31:01 +0000 (UTC) X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200