Click here to Skip to main content
15,888,208 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this gui where I used TcpClient to connect to a a device. Everything works except when I am sending/receiving data after a long pause. For example, lets say I send "hello" to the device and then wait 60 seconds before I send it again. I would get
C#
InvalidOperationException
or
C#
IOException
which make sense because the socket times out when its not doing anything for a long period. Is there a way to prevent this from happening or do I have to catch those exceptions and re-establish the connection?

thanks in advance
Posted
Comments
Jibesh 14-Dec-12 21:30pm    
Check this socket.SendTimeout property bydefault it is set to inifinite wait.are you modifying this value ?
dbzx734 14-Dec-12 21:32pm    
no i did not, it wasnt even set in my code. so what do you suggest?

You need to re-establish connection. Typically a TCP connection will time out after 30 seconds. Most TCP programs are coded with the sequence open - send - close.
 
Share this answer
 
Comments
dbzx734 14-Dec-12 21:49pm    
I thought about that, but my gui has a connect button and disconnect button because each send sequence, I want to be able to send multiple data.
You may want to rethink your gui. Just have a send button, and when the user hits it, connect - send the data - then disconnect.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900