473,854 Members | 1,471 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 13162
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
3713
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 tried this I don't see any diffents, I am sending 10Mb and the Send/BeginSend command doesn't wait till the data is on the remotepoint. Can somebody pls. explain this. Regards Robert.
5
45089
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; while(tcpSocket.Connected)
6
16684
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 returns true at this point, which I know is expected behavior, so when I reach this state, I begin sending on this socket every few seconds until an error is generated. After the exception is raised, Socket.Connected returns false.
5
3694
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 but have been unsuccessful in finding the answers so far. Either because my understanding of sockets isn't where it needs to be or my questions are too basic. My programming environment is Windows XP, Visual Studio .NET 2003 and C#. So here it...
1
16485
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 cannot detect it to take appropriate action. I am using "Connected" property of the Socket class, but it seems this property does not reflect the true state of the socket connection. Here is the code snippet. Basically, I am checking the...
13
2658
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 problem is executing the transactions against the remote server and returning the response to the remoting client. i can open the socket fine and, if i am executing one transaction at a time, everything works great. it's when my proxy server...
4
5236
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 connections and I was surprised when it did not throw an exception or do something otherwise equally nasty. It just connects and never returns any data. First, the proof that something is there and rejecting the connection (or is it that this thing...
5
3114
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 exception. Thanks Kurt
2
3688
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 smoothly without any errors but,sometimes I get the following error. "An existing connection was forcibly closed by the remote host." Why is this happening when i am not closing the client program? Could someone guide me in this issue
0
9901
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9751
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11024
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10679
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10371
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5741
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4159
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3186
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.