Re: whereis the socket mailing list



"Because it's up-side down".
"Why is that?"
"It makes replies harder to read."
"Why not?"
"Please don't top-post." - Sherm Pendley, Mac OS X Perl list



On 2/9/06, Jeff Pang <pangj@xxxxxxxxxxxxx> wrote:
ok,I'll give my question and hope get some answers from here,:-)

I have a pair of Client-Server Socket programs.When the client have finished writing the datas,it should call the 'close()' or 'shutdown()' to close the client's socket.And,when the server receive the EOF coming from client,it should call the 'close()' or 'shutdown()' to close the socket too.Then the established socket between client and server should be freed.

As we know,the close behavier under tcp socket is shown as below:

Client ---> FIN ---> Server
Client <--- ACK <--- Server

Client <--- FIN <--- Server

Server ---> ACK ---> Client



The question I want to know is,when the 'close()' call happened,if it should generate a 'FIN' and send it to another end?If it's true,then at the server end,when it receive the 'EOF' coming from client,it can delay for some time to call 'close()',so the 'FIN' should not be sent to client immediately,is it?



I think your arrows are confused down there at the bottom, but it's a
little more complicated than that. The packets sent after FIN aren't
smiple ACKs, they have different types depending on what sequence
number they have, and who's sending them. If memory serves, FIN from
the server generates a FIN_ACK from the server, which generates an
ACKPSH from the client...but don't quote me on that, it's been a long
time.

The real question here, though, is "why are you worrying about this?"
This is why standard libraries exist. People have put decads of work
into abstracting the socket layer; you don't need to reinvent the
wheel. C Programmers have the standard socket library Socket.h. In
Perl, we have the Socket (basically just a wrapper for Socket.h) and
user-friendly IO::Socket modules. Let Them worry about the connection
for you.

Just call close() or shutdown() and don't sewat the details. If you
really need to know what happens when you call close(), read the
source. The nitty gritty TCP sequencing and timing is a little bit
beyond the scope of a beginner's list.

HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [ ] blogable; [ x ] ask first; [ ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org

values of β will give rise to dom!


Relevant Pages

  • Re: TCP/IP Sockets with GNAT.Sockets
    ... > from a TCP socket in a C program we have always to code the readin a ... or with no expectation until a nonblocking socket returns ... select/poll indicates no data ready for a sufficient time (which most ... certainly provide a suitable type definition of this for you. ...
    (comp.lang.ada)
  • RE: TCP Cannot close my socket directly.... without reason ?
    ... How about a udp socket and a tcp socket? ... Here is what my client is doing. ... And I connect to the server. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Is it possible to detect TCP session term without reading pending data?
    ... > I have an application which should only read from a TCP socket if ... > detect if the TCP peer closed the connection from his side. ... poll() becomes useless to me because it only ...
    (comp.unix.programmer)
  • socket send help
    ... A simple server: ... from socket import * ... # create a TCP socket ... This happens in 2.6 or 3.0 and with different example client & server ...
    (comp.lang.python)
  • Re: TCP takes a long time to send packet
    ... > I am working on a TCP socket and I am facing this very weird problem. ... > send(sock, sendBuf, strlen(sendBuf), 0); ... requires a C-style string, not an arbitrary collection of data bytes. ...
    (comp.unix.programmer)