Core Java Technologies Technical Tips
int timeout = 500; // half a second SocketAddress socketAddress = new InetSocketAddress(host, port); Socket socket = new Socket(); socket.connect(socketAddress, timeout);
From an archive on my old blog