connect timeout for synchronous socket connection

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.
 
J

Joerg Jooss

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,
 
G

Guest

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?
 
J

Joerg Jooss

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,
 

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