You did not mark your question in any language, so I will try to cover those that I know.
I did not test any of them in production, only during development.
Python
It seems to support the setdefaulttimeout method. You can pass the number of seconds as a float or int :
import socket socket.setdefaulttimeout(10)
Java
The socket documentation claims to support java.net.Socket . According to this answer, you can specify a timeout in milliseconds , like this (10 seconds):
Socket socket = new Socket(); socket.connect(new InetSocketAddress(ipAddress, port), 10000);
Go
Using socket.DialTimeout instead of socket.Dial you can specify a timeout as time.Duration (i.e. nanoseconds ).
import ( // β¦ "appengine/socket" ) func handler(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) conn, err := socket.DialTimeout(c, "tcp", "myhost.com:1234", 10*time.Second) // β¦ }
Note that a timeout may include name resolution if you are connecting to a host name and not to an IP voice. There may also be an upper limit that is language independent, but not documented.
source share