Java Socket Create getSocket(String host, int port)

Here you can find the source of getSocket(String host, int port)

Description

get Socket

License

Open Source License

Declaration

public static Socket getSocket(String host, int port) throws IOException 

Method Source Code

//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;
    }
}

Related

  1. createSocketAddress()
  2. createSocketAddress(String server)
  3. createSocketAddrForHost(String hostName, int port)
  4. createSocketServer(int port)
  5. getSocket()
  6. getSocket(String host, int port)
  7. getSocket(String host, int port, int timeout)
  8. getSocket(String i_HostName, int i_Port)
  9. getSocketFromString(String s)