Code example for Socket

Methods: getLocalSocketAddress, getRemoteSocketAddress

0
 
    @Override 
    public String toString() {
        if (this.socket != null) {
            final StringBuilder buffer = new StringBuilder();
            final SocketAddress remoteAddress = this.socket.getRemoteSocketAddress();
            final SocketAddress localAddress = this.socket.getLocalSocketAddress();
            if (remoteAddress != null && localAddress != null) {
                NetUtils.formatAddress(buffer, localAddress);
                buffer.append("<->");
                NetUtils.formatAddress(buffer, remoteAddress);
            } 
            return buffer.toString();
        } else { 
            return "[Not bound]"; 
        } 
    } 
 
}