Here you can find the source of getSocket(String host, int port, int timeout)
public static Socket getSocket(String host, int port, int timeout) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 Robert "Unlogic" Olofsson (unlogic@unlogic.se). * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v3 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl-3.0-standalone.html ******************************************************************************/ import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; public class Main { public static Socket getSocket(String host, int port, int timeout) throws IOException { SocketAddress sockaddr = new InetSocketAddress(host, port); Socket socket = new Socket(); socket.connect(sockaddr, timeout); return socket; }/*from ww w .j a va 2 s .co m*/ }