PDA

Click to See Complete Forum and Search --> : TcpClient and "Unable to read data from the transport connection"


BtySgtMajor
Dec 16th, 2005, 10:07 AM
Hi all,

I have a client/server app running with the client using TCPClient to poll the server every 5 seconds. Everything works fine, except once every minute and five or six seconds, I'll get this:

"Unable to read data from the transport connection." (from the NetworkStream.Read() method.)

The server looks to be fine, and since I have it in a Try/Catch block, it keeps going. I've also employed a packet sniffer to have a look, and for the life of me everything looks ok (save for the fact that the app only goes to the port I want it to for any SYN requests; the rest of the time it uses a different port for some reason, which should be firewalled off, but I guess it's considered a trusted port since it's SYNching through an open port...not that I'm a network genius by any stretch of the imagnation).

The code I have looks all right and it does what I want it to. But for the life of me I cannot figure out why I'm getting this error every minute and a bit and I'd really like to get rid of it. Any thoughts?

Thanks in advance,
Duncan

dglienna
Dec 16th, 2005, 10:20 AM
Welcome to the forums!
We can't guess what you are doing, so it'd be best to post relevant sections of your code, and where the error is occurring. Also, is the error on the server or client? You may have to post both sections.

BtySgtMajor
Dec 16th, 2005, 10:28 AM
Thanks for the welcome!

The error itself is from the client. Here's pretty much what's happening in terms of (pseudo)code:

Client:

Set client receive timeout
Set client send timeout
Client.connectToServer(IP, port)
Get networkStream from client

writeStream(someInfo)
readStream() ' waits for synch

... (rest of code is similar reads and write with calls to close the network stream and client at the end, but the code always pukes on the readStream above, which simply wraps the NetworkStream object's synchronous Read method)

Server:

Server.AcceptSocket
Get networkStream from socket

readStream()
writeStream(synchMessage)

... (rest of code is similar reads and writes, with calls to close the network stream and socket at the end; I get no exceptions/errors from the server.)

Thanks again for your help!

Cheers,
Duncan

BtySgtMajor
Dec 16th, 2005, 11:08 AM
Here's another interesting twist: Both the client and server are running as services. Sometimes if I restart the client, I don't get these errors; but at some arbitrary point in time, it seems, they can start. Sometimes this amount of time is small, sometimes it's not. I'm really stumped...

BtySgtMajor
Dec 16th, 2005, 01:20 PM
An update: I've just got the same error on the server side, but only once. This is confusing the crap out of me--it's so intermittent! I don't think it's my code, but I have no way of knowing what else it could be, not being a network expert and all.