connect timeout for synchronous socket connection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

..NET Sockets does not provide a ConnectTimeout when calling the Connect
method while establishing a Synchronous socket connection. Instead, my
app is forced to wait a very long time before and Exception is thrown if the
server i'm trying to connect to is not listening.

Has anyone written any code to mimmick a connect timeout for a synchronous
socket connect? Please share.

Thanks a lot.
 
Opa said:
Hi,

.NET Sockets does not provide a ConnectTimeout when calling the
Connect method while establishing a Synchronous socket connection.
Instead, my app is forced to wait a very long time before and
Exception is thrown if the server i'm trying to connect to is not
listening.

You can specify both send and receive timeouts using
Socket.SetSocketOption(), e.g.


int timeout = 2000; // in milliseconds
socket.SetSocketOption(
SocketOptionLevel.Socket,
SocketOptionName.SendTimeout,
timeout);

Cheers,
 
The SendTimeOut option is used for timeouts on Send not initial connects.
I am using the .NET CF to connect synchronously and need to set a timeout
for the Connect method.

Any other ideas?
 
Opa said:
The SendTimeOut option is used for timeouts on Send not initial
connects. I am using the .NET CF to connect synchronously and need
to set a timeout for the Connect method.

Any other ideas?

Hm, I kind of assumed that the Send timeout applies for Connect() as
well.

Cheers,
 
Back
Top