Monday, March 5, 2012

TCP IP

1Tell the scenarios in tcp connection establishmnet in which server doesnt reply.What all kind of errors can heppen

2 When is RESET used in TCP.
Ans:
1) When connection request (SYN )arrives and no process is listening on the destination port.
This is Hard Error ECONNRFUSED is returned to client as soon as RST is  reccieved
(In UDP  ICMP port unreachable  error will be sent to host)
2) In  TCP half-open connection (in a established connection if server reboots)If clients sedns data based on Preboot connection Server responds with RST
3) Receipt of any TCP segment from any device with which the device receiving the segment does not currently have a connection (other than a SYN requesting a new connection.)
4)  Receipt of a message with an invalid or incorrect Sequence Number or Acknowledgment Number field, indicating the message may belong to a prior connection or is spurious in some other way.

example: The client's host has crashed and rebooted. Here the server will receive a response
 to its keepalive probe, but the response will be a reset, causing the server to terminate the connection
sockets API provides this capability by using the "linger on close" socket option
This causes the abort to be sent when the connection is closed, instead of the normal FIN.
--RST segment elicits no response from the other end— it is not acknowledged at all.

Q) What is Linger on option in Socket?
Answer :The effect of an setsockopt(..., SO_LINGER,...) depends on what the values in the linger structure (the third parameter passed to setsockopt()) are:
Case 1:  linger->l_onoff is zero (linger->l_linger has no meaning):
            This is the default.
On close(), the underlying stack attempts to gracefully shutdown the connection after ensuring all unsent data is sent. In the case of connection-oriented protocols such as TCP, the stack also ensures that sent data is acknowledged by the peer.  The stack will perform the above-mentioned graceful shutdown in the background (after the call to close() returns), regardless of whether the socket is blocking or non-blocking.
Case 2: linger->l_onoff is non-zero and linger->l_linger is zero:
A close() returns immediately. The underlying stack discards any unsent data, and, in the case of connection-oriented protocols such as TCP, sends a RST (reset) to the peer (this is termed a hard or abortive close). All subsequent attempts by the peer's application to read()/recv() data will result in an ECONNRESET.
Case 3: linger->l_onoff is non-zero and linger->l_linger is non-zero:
A close() will either block (if a blocking socket) or fail with EWOULDBLOCK (if non-blocking) until a graceful shutdown completes or the time specified in linger->l_linger elapses (time-out). Upon time-out the stack behaves as in case 2 above.

No comments:

Post a Comment