Archived Forum Post

Index of archived forum posts

Question:

Socket connect timeout is ignored when using a proxy

Apr 10 '17 at 15:15

Hello,

It seems that when using a socks 4/5 proxy with the Socket component, the connect timeout is ignored.

So if calling socket.Connect(hostname, port, true, 5000); I would expect to return within 5 seconds if the connection did not succeed.

However the result is that it takes around ~60 seconds, no matter what value is passed as the maxWaitMs.

In this specific case the socks proxy is working properly, although is blocked by this specific host so it will always timeout (but should respect the maxWaitMs value).

Chilkat Version: 9.5.0.66 (I have tried previous versions as well and the result is the same)


Answer

A temporary solution would be welcome as well.


Answer

I'll have a look... :)


Answer

Actually, I already know the answer. The timeout argument passed to the Connect method is just for the TCP connection establishment -- i.e. how long to wait for server to accept the TCP connection.

When a proxy is involved, there is a back-and-forth exchange of messages defined by the proxy protocol (such as SOCKS5). The timeouts for sending/receiving data on the socket are controlled by MaxReadIdleMs and MaxSendIdleMs. You would want to set these properties prior to calling Connect. The default value of these properties is 0, which means to wait forever, but I suspect that internally Chilkat is capping the timeouts (for the case of proxy connection establishment) to 60 seconds. I'll double-check...