|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
TCPClient - Detectiing loss of remote host connectionBefore I go and make massive changes to a TCP/IP library I made, I was
wondering if the detection of connection loss is possible through the TCPClient class. The problem I have is that I make a connection to another application using a TCPClient in one app and a Listener with Client in the other app. I close the app with the listener. I then try to send data to the listener app. TCPClient.Connected returns true after the remote connection is forcefully closed. I understand that the value of TCPClient.Connect is based on the success of the previous send/recieve action. When I perform a send operation, there is no exception thrown. Trying to perform a send operation a second time throws a socket exception stating the connection was closed at the remote end. I was hoping that the exception would be thrown on the first send operation after the connection was closed. Any way around this or will I have to send test bytes at the start of each send operation in order to test the integrity of the TCP connection? Any help would be great thanks :o) i remember for Socket class .... Receive and Callback for asynchronous
receive returns with 0 byte to read ...... i have never used TcpClient though ....... Show quote "Andrew McNab" <AndrewMc***@discussions.microsoft.com> wrote in message news:CDF4AA23-B512-41F2-BDC5-D598235C41DC@microsoft.com... > Before I go and make massive changes to a TCP/IP library I made, I was > wondering if the detection of connection loss is possible through the > TCPClient class. > > The problem I have is that I make a connection to another application > using > a TCPClient in one app and a Listener with Client in the other app. I > close > the app with the listener. I then try to send data to the listener app. > TCPClient.Connected returns true after the remote connection is forcefully > closed. I understand that the value of TCPClient.Connect is based on the > success of the previous send/recieve action. When I perform a send > operation, > there is no exception thrown. Trying to perform a send operation a second > time throws a socket exception stating the connection was closed at the > remote end. > > I was hoping that the exception would be thrown on the first send > operation > after the connection was closed. Any way around this or will I have to > send > test bytes at the start of each send operation in order to test the > integrity > of the TCP connection? Any help would be great thanks :o) This is one of those issues I would love to be able remember perfectly, but
never seem to be able to. But basically, if you think about the stream nature of tcp (has nothing to do with TcpClient) having it work the way you want would be the worst kind of blocking operation - blocking on a high latency network call. You would need to wait for each send to reach host *and get a ack. You would not want that. IIRC, you could actually manage to send multiple sends before every getting the error because of buffering and Nagel. A common way to handle this is in your protocol. A typical send/request would do in many cases. You do you send and sync or async wait for a reply. You can error on the reply if you don't get in x seconds for example. -- Show quoteWilliam Stacey [C# MVP] PCR concurrency library: www.codeplex.com/pcr PSH Scripts Project www.codeplex.com/psobject "Andrew McNab" <AndrewMc***@discussions.microsoft.com> wrote in message news:CDF4AA23-B512-41F2-BDC5-D598235C41DC@microsoft.com... | Before I go and make massive changes to a TCP/IP library I made, I was | wondering if the detection of connection loss is possible through the | TCPClient class. | | The problem I have is that I make a connection to another application using | a TCPClient in one app and a Listener with Client in the other app. I close | the app with the listener. I then try to send data to the listener app. | TCPClient.Connected returns true after the remote connection is forcefully | closed. I understand that the value of TCPClient.Connect is based on the | success of the previous send/recieve action. When I perform a send operation, | there is no exception thrown. Trying to perform a send operation a second | time throws a socket exception stating the connection was closed at the | remote end. | | I was hoping that the exception would be thrown on the first send operation | after the connection was closed. Any way around this or will I have to send | test bytes at the start of each send operation in order to test the integrity | of the TCP connection? Any help would be great thanks :o) |
|||||||||||||||||||||||