List of utility methods to do Socket Create
Socket | getSocket(String host, int port) get Socket if (host == null || port == -1) throw new IllegalArgumentException("Missing required arguments: host and/or port"); return new Socket(host, port); |
Socket | getSocket(String host, int port) get Socket return getSocket(host, port, false);
|
Socket | getSocket(String host, int port, int timeout) get Socket SocketAddress sockaddr = new InetSocketAddress(host, port); Socket socket = new Socket(); socket.connect(sockaddr, timeout); return socket; |
Socket | getSocket(String i_HostName, int i_Port) get Socket if (i_Port <= 0 || i_Port > 65535) { throw new IndexOutOfBoundsException("Port isn't between 0 and 65535."); Socket v_Ret = null; try { InetAddress v_InetAddress = InetAddress.getByName(i_HostName); if (v_InetAddress != null) { v_Ret = new Socket(v_InetAddress, i_Port); ... |
Socket | getSocketFromString(String s) get Socket From String Socket result = null; String[] splitAddress = s.split(":"); if (splitAddress.length > 1) { String hostname = splitAddress[0]; int port = Integer.parseInt(splitAddress[1]); result = new Socket(hostname, port); return result; ... |
String | getSocketId(Socket socket) get Socket Id InetAddress inetAddress = socket.getInetAddress(); String hostName = ""; if (inetAddress != null) { hostName = inetAddress.getHostName(); return hostName + ":" + socket.getPort() + ":" + socket.hashCode(); |
ServerSocket | getSocketInRange(int minPort, int maxPort, boolean random) Choose a port from the specified range - either sequentially, or at random. ServerSocket s = null; int port = minPort - 1; Random r = new Random(System.currentTimeMillis()); while (s == null && port <= maxPort) { if (random) port = minPort + r.nextInt(maxPort - minPort); else port++; ... |
byte[] | getSocketToBytes(String ip, int port, String packet, int timeout) get Socket To Bytes Socket socket = null; DataOutputStream dos = null; DataInputStream dis = null; byte buff[] = new byte[BUFF_SIZE]; try { socket = new Socket(); SocketAddress socketAddress = new InetSocketAddress(ip, port); socket.connect(socketAddress, timeout); ... |
Socket | getSocketToProxyServer(String host, int port) get Socket To Proxy Server Socket socket = new Socket(); socket.connect(new InetSocketAddress(host, port), 1000); socket.setSoTimeout(300000); return socket; |