asynchronous socket timeout

sdlangers

Well-known member
Joined
Dec 3, 2002
Messages
118
Hi All,

Anyone know how to set the timeout value for a client socket thats trying to asynchronously connect to a server.

I know this seems dumb since its connecting asynchronously, but id still like to shorten the timeout value.

For example :

Code:
client = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP)
 set timeout value
 client.timeout ????
 asynchronous connect        
client.BeginConnect(EP, AddressOf sockconnected, client)

Thanks
 
I dont believe so, only for sending and receiving data. I asked a friend, and he doesnt believe BSD sockets offer a way of doing this, he has unsuccessful in finding a way to do it with winsock and win32 either.

Your best bet is probably to use a timer and do it yourself.
 
Hi,

Thanks for your help.. ok, so if i use a timer.. how do i end the connection attempt after starting it asynchronously?.. i.e. would it not still try to fire the callback function whenever it does timeout?

Thanks again for your help - im new enough to sockets
 
I guess you could attempt to call the .Close method. Its not something Ive ever had to do so I dont know. I guess if you closed the socket and disposed it, the callback wouldnt fire.
 
Long time in comming but here is a response

m_DataSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 60000);
m_DataSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 60000);

This is more for people who are lookign for the answer now then to answer your question. I was looking and happend to find it in some example of FTP. Anyway, here it is.
 
Back
Top