473,509 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket.Send() succeeds, but remote end point closed the connection

Hi,

Here is my client/server scenario:
Step1: Client connects to server and sends data sucessfully (using
Socket.Send()).
Step2: Server gracefully exists (calls Socket.Shutdown() and
Socket.Close()). I see the server connection status go from ESTABLISHED to
FIN_WAIT2, the client connection go from ESTABLISHED to WAIT_CLOSE.
Step3: client.Send() succeeds and return the number of bytes sent (over the
closed connection!)
Step4: same as step3, Send() throws, which is expected, but was expected in
step3

Question 1: Shouldn't step3 behave like step4? If step3 can happen, then the
transport is not reliable.
Question 2: Is there a socket status event the client can subscribe to?

Thanks
Jun 13 '06 #1
2 13122
yvan wrote:
Hi,

Here is my client/server scenario:
Step1: Client connects to server and sends data sucessfully (using
Socket.Send()).
Step2: Server gracefully exists (calls Socket.Shutdown() and
Socket.Close()). I see the server connection status go from ESTABLISHED to
FIN_WAIT2, the client connection go from ESTABLISHED to WAIT_CLOSE.
Step3: client.Send() succeeds and return the number of bytes sent (over the
closed connection!)
Step4: same as step3, Send() throws, which is expected, but was expected in
step3

Question 1: Shouldn't step3 behave like step4? If step3 can happen, then the
transport is not reliable.
Question 2: Is there a socket status event the client can subscribe to?

....

This is by design of TCP protocol.

What you describe is not graceful close by server. In CLOSE_WAIT state,
send is allowed. CLOSE_WAIT means that other side has shutdown it's
outgoing side of connection (you will not receive any data on that
connection), but you may send until you shutdown your side (remember
that tcp is full-duplex). Server should not exit or call close on socket
until it has receive shutdown from other side (it has to make transition
from FIN_WAIT2 to TIME_WAIT state).

Gracefull close is:
Server calls Shutdown with SD_SEND
client receives close notification (read will return 0)
client may send data and call shutdown with SD_SEND when finished
server must loop in read until it receives close notification (receive 0
from read). Only then it may close socket.

Only if you close gracefully, you are sure data is delivered. Please
note that there are linger options that can be set which affect this
Check in MSDN:

http://msdn.microsoft.com/library/de..._closure_2.asp

Send does not ensure data is sent, it ensures only it is buffered by the
OS (TCP protocol). IOW, number of bytes returned from send call > 0 does
not mean data is received by other side.
Regards,
Goran
Jun 14 '06 #2
Goran,

Thanks for taking the time to answer, this is really helpful.

"Goran Sliskovic" wrote:
yvan wrote:
Hi,

Here is my client/server scenario:
Step1: Client connects to server and sends data sucessfully (using
Socket.Send()).
Step2: Server gracefully exists (calls Socket.Shutdown() and
Socket.Close()). I see the server connection status go from ESTABLISHED to
FIN_WAIT2, the client connection go from ESTABLISHED to WAIT_CLOSE.
Step3: client.Send() succeeds and return the number of bytes sent (over the
closed connection!)
Step4: same as step3, Send() throws, which is expected, but was expected in
step3

Question 1: Shouldn't step3 behave like step4? If step3 can happen, then the
transport is not reliable.
Question 2: Is there a socket status event the client can subscribe to?

....

This is by design of TCP protocol.

What you describe is not graceful close by server. In CLOSE_WAIT state,
send is allowed. CLOSE_WAIT means that other side has shutdown it's
outgoing side of connection (you will not receive any data on that
connection), but you may send until you shutdown your side (remember
that tcp is full-duplex). Server should not exit or call close on socket
until it has receive shutdown from other side (it has to make transition
from FIN_WAIT2 to TIME_WAIT state).

Gracefull close is:
Server calls Shutdown with SD_SEND
client receives close notification (read will return 0)
client may send data and call shutdown with SD_SEND when finished
server must loop in read until it receives close notification (receive 0
from read). Only then it may close socket.

Only if you close gracefully, you are sure data is delivered. Please
note that there are linger options that can be set which affect this
Check in MSDN:

http://msdn.microsoft.com/library/de..._closure_2.asp

Send does not ensure data is sent, it ensures only it is buffered by the
OS (TCP protocol). IOW, number of bytes returned from send call > 0 does
not mean data is received by other side.
Regards,
Goran

Jun 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3673
by: Robert A. van Ginkel | last post by:
In news:OZ0W9RsdDHA.2432@TK2MSFTNGP10.phx.gbl... I ask the question how I can see if all the data is on the other side of the connection. I got as answer that I should use the blocking property. I...
5
44945
by: Morten | last post by:
How do I detect if a client socket is no longer connected to the listen tcp socket ? I have tried with (just an example): --------------------- Socket tcpSocket; ...
6
16623
by: Bruce Vander Werf | last post by:
I am using the asynchronous send/receive methods of the Socket class. When the remote end closes the socket, the callback for receive is called and EndReceive returns 0. Socket.Connected still...
5
3669
by: John Sheppard | last post by:
Hi all, I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose...
1
16396
by: Dr. J | last post by:
I have an application that opens a socket and connects to another application listening over a port. The problem I am encountering is that when the listening application is closed my application...
13
2632
by: coloradowebdev | last post by:
i am working on basically a proxy server that handles requests via remoting from clients and executes transactions against a third-party server via TCP. the remoting site works like a champ. my...
4
5212
by: schwehr | last post by:
Hi All, I've tried to RTFM this and am having no luck. First off, I am using Mac OSX 10.4.7 with python 2.4.2 from fink. I am trying to connect to a server that should be rejecting...
5
3075
by: Kurt | last post by:
I have a client & server app which communicates using the socket class. If I shutdown the server closing the socket the client still thinks the socket is open. Even calling send does not throw an...
2
3642
by: manasap | last post by:
Hi all! I've written a server and a client application using asynchronous sockets.The client sends data packets for every 7 seconds.The server receives the packets. This process proceeds...
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7067
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.