List of utility methods to do Socket Address Get
int | compareAddresses(InetSocketAddress addr1, InetSocketAddress addr2) compare Addresses byte[] addr1Array = addr1.getAddress().getAddress(); byte[] addr2Array = addr2.getAddress().getAddress(); for (int i = 0; i < addr1Array.length && i < addr2Array.length; i++) if (addr1Array[i] < addr2Array[i]) return -1; int port1 = addr1.getPort(); int port2 = addr2.getPort(); if (port1 < port2) ... |
String | convertToHostString(SocketAddress hostAddress) convert To Host String final StringBuilder host = new StringBuilder(); final InetSocketAddress inetSocketAddr = (InetSocketAddress) hostAddress; final InetAddress addr = inetSocketAddr.getAddress(); if (addr instanceof Inet6Address) { host.append('['); host.append(addr.getHostAddress()); host.append(']'); } else if (addr != null) { ... |
SocketAddress | create(SocketAddress address, SocketAddress port) Creates and returns a SocketAddress . if (isUnresolved(address)) { return createUnresolved(getHostName(address), getPort(port)); } else { return createResolved(getAddress(address), getPort(port)); |
ServerSocket | createBoundServerSocket(final SocketAddress socketAddress) create Bound Server Socket final ServerSocket serverSocket = new ServerSocket(); serverSocket.bind(socketAddress); return serverSocket; |
Socket | createClientSocket(InetSocketAddress site) create Client Socket Socket socket = new Socket(); socket.setTcpNoDelay(true); socket.setReceiveBufferSize(RECV_BUF_SIZE); socket.setSendBufferSize(SEND_BUF_SIZE); socket.bind(null); socket.connect(site); return socket; |
ArrayList | createHttpFields(InetSocketAddress endpoint) create Http Fields ArrayList<String> fields = new ArrayList<String>(); fields.add("Connection: Upgrade"); return fields; |
InetSocketAddress | createInetSocketAddress(String address) Creates an InetSocketAddress given a host and optional port in a single String This allows either IP4 or IP6 addresses (including port) to be provided as Strings as per rfc2732 return createInetSocketAddress(address, 0);
|
InetSocketAddress | createInetSocketAddress(String ip, int port) create Inet Socket Address InetSocketAddress address = null; if (ip == null) { address = new InetSocketAddress(port); } else { address = new InetSocketAddress(ip, port); return address; |
String | describe(InetSocketAddress localAddress) describe return String.format("local.address == %s", localAddress); |
InetSocketAddress | encodedStringToInetSocketAddress(String str) encoded String To Inet Socket Address byte[] buf = str.getBytes(CHARSET); int port = (int) (buf[buf.length - 2] << 8) + (buf[buf.length - 1] & 255); return new InetSocketAddress(InetAddress.getByAddress(Arrays.copyOfRange(buf, 0, 4)), port); |