Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Timeouts in TcpSocket.ClientConnect()
#1
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?

Thanks
#2
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...
#3
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.
#4
try this

Member function TcpSocket.ClientConnectT
Code:
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 "www.xxx.com"), or computer name, or IP ("xxx.xxx.xxx.xxx").
;;;To connect to a server on this computer, can be used "localhost" or "127.0.0.1" 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
__TCPSOCK_CLIENTCONNECT* x._new
x.server=server; x.port=port

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

if x.isError ;;x.sock.ClientConnect error
,_s=x.server
,x._delete
,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)
x._delete


#sub Thread
function __TCPSOCK_CLIENTCONNECT*x

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)