Here you can find the source of getSocket(String host, int port)
public static Socket getSocket(String host, int port) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.Socket; import java.util.HashMap; public class Main { private static HashMap<String, Socket> sockets = new HashMap<String, Socket>(); public static Socket getSocket(String host, int port) throws IOException { return getSocket(host, port, false); }/*w w w . ja v a 2 s . c om*/ public static Socket getSocket(String host, int port, boolean reset) throws IOException { Socket socket = sockets.get(host + ":" + port); if (socket == null || socket.isClosed() || reset) { socket = new Socket(host, port); socket.setKeepAlive(true); sockets.put(host + ":" + port, socket); } return socket; } }