Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Timeouts in TcpSocket.ClientConnect()
Hi -

I know how to trap timeouts in TcpSocket.Send() using TcpSocket.Recieve() - but I'm also getting timeout errors on TcpSocket.ClientConnect().

The root cause of this is that the DNS at my institution is a mess. I have a fallback mechanism where the IP addresses are cached in a local database and if there is a timeout on ClientConnect() it will look up the IP address in the database. While this is a complete kludge - it works well except that it can take 10-15 seconds for the initial timeout. Is there a mechanism for setting the timeout of the initial connection lower?

Try to debug to find which function fails. Is it gethostbyname/gethostbyaddr, or sock_connect? I guess it is gethostx.
The API don't allow to set timeouts, or I don't know how. But we can try to call it in other thread...
It's in sock_connect. So - I'll try making things non-blocking and putting in a timeout of 1 second or so. I'm on a very fast network with a flaky DNS :-). I'll try to get this working and let you know how it goes.
try this

Member function TcpSocket.ClientConnectT
Copy      Help
function $server @port [^timeoutS]

;Creates client socket and connects to server. Same as ClientConnect but with timeout.
;Error if failed.

;server - server address (eg ""), or computer name, or IP ("").
;;;To connect to a server on this computer, can be used "localhost" or "" or "".
;port - port number.
;timeoutS - if 0, just calls ClientConnect. Else calls ClientConnect in other thread and waits max timeoutS s; error on timeout.

opt noerrorshere 1
if(!timeoutS) ret ClientConnect(server port)

if(m_socket) Close

type __TCPSOCK_CLIENTCONNECT TcpSocket'sock ~server @port !freeThis !isError
x.server=server; x.port=port

wait timeoutS H mac("sub.Thread" "" x)
err ;;timeout
,end _error

if x.isError ;;x.sock.ClientConnect error
,end _s

;success. Copy from x.sock to this, and clear x.sock to disable dtor.
memcpy &this &x.sock sizeof(TcpSocket)
memset &x.sock 0 sizeof(TcpSocket)

#sub Thread

x.sock.ClientConnect(x.server x.port)
err if(!x.freeThis) x.server=_error.description; x.isError=1
if(x.freeThis) x._delete ;;timeout

Forum Jump:

Users browsing this thread: 1 Guest(s)