Login  
Search All Forums
Dart Home | PowerTCP Sockets for .NET | Custom Development Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
AuthorForum: PowerTCP Sockets for .NET (Secure and Standard)
Topic: Client Network Cable Disconnected
premier1st

From: Fayetteville, GA USA
Posts: 11
Member Since: 06/10/04
posted June 10, 2004 8:58 AM

If am using the Try Catch Finally way to determine when clients disconnect from the server.

Problem: In testing for an ISP failure on the client's end I unplug the network cable fromt he client box. Server NEVER gets a disconnect notification.

I really don't feel like reinventing the wheel and can only assume someone has come across this? Surely you guys at Dart have anticipated a Network failure on both the Client and Server end and have ways to clear out connections on the server and have the client know if it or the server has lost network connectivity.

I am on the evaluation of your product and will not purchase until I know, for certain, I can overcome this issue.

Asside from this ONE issue I am finished development on my Application using the eval. If you can send me code or point me in the right direction to a DIFINITIVE answer I will purchase and be done.

Great product though...I am impressed with the ease of use...over the standard socket support in .NET

-- Patrick
premier1st

From: Fayetteville, GA USA
Posts: 11
Member Since: 06/10/04
posted June 10, 2004 10:11 AM

Also, I took the Echo Server and TCPClient without any modifications and tested the same scenerio. If I unplug the network cable from the client computer after connecting to the echo server, the echo server never knows the client connected and keeps the thread alive.

That would result in many many many useless open threads over a days time. You would need to manually close down and re-open the server daily just to clean out all the wasted threads. Not acceptable.
premier1st

From: Fayetteville, GA USA
Posts: 11
Member Since: 06/10/04
posted June 10, 2004 4:36 PM

This can't be that hard... is anyone atleast looking into this. I have been working with sockets directly and have found that socket.poll and socket.select are all unreliable methods for determining when a socket is disconneted.

Would it be logical to say one might have to set up a new timer thread to ping all connected clients on an interval? (5 minutes or so)?
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted June 14, 2004 10:56 AM

In order to determine if the connection has been "severed" like this, you would have to enable keep-alive on your system and then set the KeepAlive property to true in our control.

I tested it and it works in the scenario you describe.

Here is a link to an article that describes enabling KeepAlive:

http://www.winguides.com/registry/display.php/891

You may have to experiment with the timeout settings. You will have to reboot if you make changes.
premier1st

From: Fayetteville, GA USA
Posts: 11
Member Since: 06/10/04
posted June 14, 2004 6:25 PM

SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.KeepAlive, 7200)

Does this not have the same effect without having to go thru the registry and rebooting.
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted June 14, 2004 9:02 PM

No. As far as I know, Keep-Alive does not work unless you make those registry changes.
premier1st

From: Fayetteville, GA USA
Posts: 11
Member Since: 06/10/04
posted June 15, 2004 7:41 AM

So microsoft created a completely useless method on the socket class. Hmmm, it has to do something.

Soo, are you saying that I set the keepalive on my network machine ONLY. That will allow it to know to remove all the clients when a network connection is broken?
premier1st

From: Fayetteville, GA USA
Posts: 11
Member Since: 06/10/04
posted June 15, 2004 8:19 AM

I did the keepalive thing and it did work. Now I have 1 final question. During the time the client connection is still on the server, before it is removed by the keepalive, I am still able to send data.

Where does the data go when sent to a disconnected client object?

What are the consequences of performing such an action. If there is no major performance issue, I will just send data as normal.

If there is, will I need to send a ping/pong from server to client with a receive timeout on the pong from the client before trying to send the real data...or would that be a waste?

Would the overhead of always sending ping/pongs to every client before every send be worst than send data to a client that doesn't really exist anymore?
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted June 15, 2004 9:15 AM

You should get an error when the Send times out. By default SendTimeout = 0 (never) so try setting it to 3000 sec and see what happens.
premier1st

From: Fayetteville, GA USA
Posts: 11
Member Since: 06/10/04
posted June 15, 2004 6:22 PM

I went with the keepalive on my server and now my server always knows when the client or itself has lost a connection. Problem: For some reason, I used to be able to disconnect the network cable from the client and the client would eventually know it was disconnected...2 minutes max. Now it no longer knows. It sits indifinitely thinking it is connected. Any ideas? does the registry on the client machine need to be modified for keepalives to get around the 2 hour barrier? That would not be possible once I release.

Am I going to have to make my client manually ping the server every so often?

I did test that if I issue a request from my client to my server and the connection is broke, the client throws a "forcibly" disconnected error.
premier1st

From: Fayetteville, GA USA
Posts: 11
Member Since: 06/10/04
posted June 15, 2004 6:30 PM

I take that last post back on the client knowing it is disconnected when I issue a request.

It was just a conincidence that when I issued the request it was notified of a disconnect.

It appears that there is not real set time limit on my client to know when to check for a connection. Sometimes I knows in 1 minutes, and earlier it was about 45 minutes.

I would like to have a set in stone 5 minute check. I do not want my client or my server sitting there for more than 5 minutes thinking they are connected when they are not.

It seems odd that something so important can be so hard to nail down. How does MSN Messenger and AOL Instant Messenger do this.

Also, with the keepalive on my server set to 5 minutes (globally) wouldn't that possibly have a negative impact on network traffic? Especially since I will be placing this server piece on my companies web server...? Could it slow down all network activity in and out of my webserver?
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted June 16, 2004 9:43 AM

If you don't have a pending send or receive to timeout, then you won't get an error when the network cable is unplugged (unless you enable keep-alive)

In regards to performance, yes it may hinder performance on the server to enable keep-alive. That is something to consider. There must be a reason why MS disabled it by default.

In regards to MSN and AOL, they probably have some sort of handshake they do every once in awhile to determine the state of connectivity.

premier1st

From: Fayetteville, GA USA
Posts: 11
Member Since: 06/10/04
posted June 16, 2004 10:54 AM

With that in mind, if you have a client set to Autoreceive - which puts the client in Asynch read mode and you send a ping/handshake to the server, there is no way to place a timeout on the receive, nor have I found out a way to stop the async receive, start a sync read, and restart the async receive without closing and reopening the socket. I went down that road and hit a brick wall.

Major circle jerk.

In short, tell me if I am wrong, if you are using a client in async mode, there is no way to just stop the read without closing the connection... to get into a sync mode to enable the receive timeout. Is that correct?

For my client I am using one of your tcp client examples and really don't want to have to go changing it up. It seems to close and read quite well when it is connected and disconnected properly.
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted June 16, 2004 11:09 AM

That's true. The only way to abort a pending receive or send is to abort the connection.
premier1st

From: Fayetteville, GA USA
Posts: 11
Member Since: 06/10/04
posted June 16, 2004 2:16 PM

Ok, I have done it. I removed all keepalives because I do not want to take any chances with network problems.

I have both the client and the server sitting in sync reads with the server on a 5 minute timeout and the client on a 5 minute timeout.

The client sends a ping every 4:30 minutes, the server then sends a pong back to the server.

Handshake - both client and server must get some form of communication within 5 minutes... whether from the ping/pong or other data transmission.

One more question. If my client sends a ping to the server, the server sends back the pong and immediately is required to send normal data (can occur anytime but just happens to occur on the heals of the ping) what happens.

If the client is sitting waiting in a sync mode, gets the pong... are the controls smart enough to catch the next set of data.... does the data sit out there waiting for the client to start accepting it. Is the client's receipt considered to be blocked and thus an error will raise on the server?

How does back to back data get handled in a sync read / blocking more?

Before, when I was in async, I was comfortable knowing that no matter what my server sent, it would always get to the client without being blocked because each receipt was on a different thread.
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted June 16, 2004 2:45 PM

Data that comes in is buffered up by us and delivered to you when you call Receive.

Data that comes in while you are receiving will not be lost.
premier1st

From: Fayetteville, GA USA
Posts: 11
Member Since: 06/10/04
posted June 18, 2004 6:38 AM

Thanks so much. Looks like I finally have everything under control. We have it released to our beta site and they have been up for a day now without any problems. Appreciate all the help.
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted June 18, 2004 8:40 AM

That's good to hear! Thanks for following up.
Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX