Java Socket Address Get cast2SocketAddress(String addr)

Here you can find the source of cast2SocketAddress(String addr)

Description

cast Socket Address

License

Apache License

Declaration

public static SocketAddress cast2SocketAddress(String addr) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.net.InetSocketAddress;
import java.net.SocketAddress;

public class Main {
    public static SocketAddress cast2SocketAddress(String addr) {
        String[] str = addr.split(":");
        if (str.length != 2)
            throw new IllegalArgumentException();
        return new InetSocketAddress(str[0], Integer.valueOf(str[1]));
    }/*from   w w w  .  ja  v  a2 s . c  om*/

    public static SocketAddress cast2SocketAddress(long id) {
        StringBuffer host = new StringBuffer(30);

        host.append((id & 0xff)).append('.');
        host.append(((id >> 8) & 0xff)).append('.');
        host.append(((id >> 16) & 0xff)).append('.');
        host.append(((id >> 24) & 0xff));

        int port = (int) ((id >> 32) & 0xffff);

        return new InetSocketAddress(host.toString(), port);
    }
}

Related

  1. addressLabel(SocketAddress localAddress, SocketAddress remoteAddress)
  2. addressMapToString( Map> map)
  3. addressToString(InetSocketAddress a)
  4. addressToString(InetSocketAddress address, Boolean useIpAddress)
  5. asString(SocketAddress socketAddress)
  6. compareAddresses(InetSocketAddress addr1, InetSocketAddress addr2)
  7. convertToHostString(SocketAddress hostAddress)
  8. create(SocketAddress address, SocketAddress port)
  9. createBoundServerSocket(final SocketAddress socketAddress)