Socket.ReceiveTimeOut Problem
-
Hi All, When I set the ReceiveTimeOut of Socket to some milliseconds then Socket throws the timeout Exception while the period expires and the problem is that then Socket is disconnected therefore i am unable to send and receive again with this socket. I want that it waites for sometime for receiving but after elapsing the time,it should not be disconnected so that i can use it again n again.. Plz help...Its urgent. Best Regards, Lalit Narayan
-
Hi All, When I set the ReceiveTimeOut of Socket to some milliseconds then Socket throws the timeout Exception while the period expires and the problem is that then Socket is disconnected therefore i am unable to send and receive again with this socket. I want that it waites for sometime for receiving but after elapsing the time,it should not be disconnected so that i can use it again n again.. Plz help...Its urgent. Best Regards, Lalit Narayan
From MSDN: The ReceiveTimeout property determines the amount of time that the Read method will block until it is able to receive data. This time is measured in milliseconds. If the time-out expires before Read successfully completes, TcpClient throws a IOException. There is no time-out by default. Read more here[^]. Kind regards,
The only programmers that are better C# programmers, are those who look like this -> :bob:
:java: Programm3r My Blog: ^_^
-
From MSDN: The ReceiveTimeout property determines the amount of time that the Read method will block until it is able to receive data. This time is measured in milliseconds. If the time-out expires before Read successfully completes, TcpClient throws a IOException. There is no time-out by default. Read more here[^]. Kind regards,
The only programmers that are better C# programmers, are those who look like this -> :bob:
:java: Programm3r My Blog: ^_^
-
But when the socket throws exception ,socket is disconnected...this creates the problem 4 me,plz give the solution so that the socket should not be disconnected. Best Regards, Lalit Narayan
I think that is what happens when the time-out period is exceeded, the Receive method will throw a SocketException. Have you tried catching the exception, checking whether the socket is still connected (see here[^]), if not try to reconnect...
The only programmers that are better C# programmers, are those who look like this -> :bob:
:java: Programm3r My Blog: ^_^
-
I think that is what happens when the time-out period is exceeded, the Receive method will throw a SocketException. Have you tried catching the exception, checking whether the socket is still connected (see here[^]), if not try to reconnect...
The only programmers that are better C# programmers, are those who look like this -> :bob:
:java: Programm3r My Blog: ^_^
Hi, Actually i am working on Server Side,the connection requests comes from the Client Side,i can not reconnect to the Client through Socket.... The Server has TCP Listener on its own side,that waits for the Connection Request from the Client and make the Socket after Accepts the request. Best Regards, Lalit Narayan
-
Hi, Actually i am working on Server Side,the connection requests comes from the Client Side,i can not reconnect to the Client through Socket.... The Server has TCP Listener on its own side,that waits for the Connection Request from the Client and make the Socket after Accepts the request. Best Regards, Lalit Narayan
As far as my understanding of TCP/IP clients and server(s) goes; it is the client initiates the connection. So, if the client disconnect in any way from the server, when it is the clients 'responsibility' to reconnect to the server. Kind regards,
The only programmers that are better C# programmers, are those who look like this -> :bob:
:java: Programm3r My Blog: ^_^
-
As far as my understanding of TCP/IP clients and server(s) goes; it is the client initiates the connection. So, if the client disconnect in any way from the server, when it is the clients 'responsibility' to reconnect to the server. Kind regards,
The only programmers that are better C# programmers, are those who look like this -> :bob:
:java: Programm3r My Blog: ^_^
Hi, The Client Side Code is written in C at Embeded Side n it takes some time to show the status "Disconnected" this creates the problem 4 me,they find the state of Socket "Connected" while it is disconnected at Server Side... Plz do the needful. Thanks and Regards, Lalit Narayam
-
Hi, The Client Side Code is written in C at Embeded Side n it takes some time to show the status "Disconnected" this creates the problem 4 me,they find the state of Socket "Connected" while it is disconnected at Server Side... Plz do the needful. Thanks and Regards, Lalit Narayam
Well it seems to me that the embedded side needs some works?! :^)
lnmca wrote:
The Client Side Code is written in C at Embeded Side n it takes some time to show the status "Disconnected" this creates the problem 4 me,they find the state of Socket "Connected" while it is disconnected at Server Side
You cannot build on something if it is not working correctly.. X|
The only programmers that are better C# programmers, are those who look like this -> :bob:
:java: Programm3r My Blog: ^_^
-
Hi All, When I set the ReceiveTimeOut of Socket to some milliseconds then Socket throws the timeout Exception while the period expires and the problem is that then Socket is disconnected therefore i am unable to send and receive again with this socket. I want that it waites for sometime for receiving but after elapsing the time,it should not be disconnected so that i can use it again n again.. Plz help...Its urgent. Best Regards, Lalit Narayan
Well, I think you can't do that. Imagine the situation: Server starts reading. Client starts sending. But, for some reason, the connection is VERY slow. Server then receives the time-out (imagine it does not disconnect). The server then asks for more data... but, the client is still sending the old-data. So, the server must now wait for what? The old data? The new data? How will it differentiate one data from the other? I think the fact the connection is closed is on purpose. If you want, I think you may NOT use the ReceiveTimeOut. Instead, create another thread to call "abort" in the reading thread if it takes too long, so the connection will not be aborted, but I don't really know what will happen with the data in this case. Also, depending on your requirements, it's possible to use UDP to receive the data.