TcpClient app hangs when connection gets lost

M

Mathijs

Hi,

I have a small Compact Framework tcpclient application (c#).

This is my connection procedure:

tcpclient = new TcpClient(ip, port);
stream = tcpclient.GetStream();
Sent("HELLO");
stream.BeginRead(ReadBuffer, 0, ReadBuffer.GetLength(0), new
AsyncCallback(DataAvailableCallback), null);


Sent does a stream.Write(). DataAvailableCallback calls the
CommandHandler OnNewCommand, which triggers a function in the GUI part
of the application.

Everything works well (the commands received via the TcpClient are
processed) until I shutdown the server (simulate a network harsh
error?). Then, the GUI part of the application just hangs. I have no
idea where exactly the application hangs.

Any tips for me?

Thanks in advance,
Mathijs.
 
M

Mathijs

Mathijs said:
error?). Then, the GUI part of the application just hangs. I have no
idea where exactly the application hangs.

More info: the GUI only hangs when running the application from the
debugger. Still unexplainable for me, but more acceptable.

I check tcpclient.Client.Connected (via a timer event) to check if I'm
still connected after I shut down the server. It keeps continuing
'True'. Am I checking the wrong property? Are there other ways to check
if the connection is still alive?

Thanks,
Mathijs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top