Java Code Examples for java.net.Socket.getLocalSocketAddress()

The following are Jave code examples for showing how to use getLocalSocketAddress() of the java.net.Socket class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: java-android-websocket-client   File: BHttpConnectionBase.java   Source Code and License Vote up 6 votes
@Override
public String toString() {
    final Socket socket = this.socketHolder.get();
    if (socket != null) {
        final StringBuilder buffer = new StringBuilder();
        final SocketAddress remoteAddress = socket.getRemoteSocketAddress();
        final SocketAddress localAddress = socket.getLocalSocketAddress();
        if (remoteAddress != null && localAddress != null) {
            NetUtils.formatAddress(buffer, localAddress);
            buffer.append("<->");
            NetUtils.formatAddress(buffer, remoteAddress);
        }
        return buffer.toString();
    } else {
        return "[Not bound]";
    }
}
 
Example 2
Project: BiglyBT   File: TransportStartpointTCP.java   Source Code and License Vote up 6 votes
@Override
public InetSocketAddress
getAddress()
{
	SocketChannel channel = ep.getSocketChannel();

	if ( channel != null ){

		Socket socket = channel.socket();

		if ( socket != null ){

			return((InetSocketAddress)socket.getLocalSocketAddress());
		}
	}

	return( null );
}
 
Example 3
Project: lighthouse   File: BHttpConnectionBase.java   Source Code and License Vote up 6 votes
@Override
public String toString() {
    final Socket socket = this.socketHolder.get();
    if (socket != null) {
        final StringBuilder buffer = new StringBuilder();
        final SocketAddress remoteAddress = socket.getRemoteSocketAddress();
        final SocketAddress localAddress = socket.getLocalSocketAddress();
        if (remoteAddress != null && localAddress != null) {
            NetUtils.formatAddress(buffer, localAddress);
            buffer.append("<->");
            NetUtils.formatAddress(buffer, remoteAddress);
        }
        return buffer.toString();
    } else {
        return "[Not bound]";
    }
}
 
Example 4
Project: neoscada   File: NioSocketSession.java   Source Code and License Vote up 5 votes
/**
 * {@inheritDoc}
 */
public InetSocketAddress getLocalAddress() {
    if (channel == null) {
        return null;
    }

    Socket socket = getSocket();

    if (socket == null) {
        return null;
    }

    return (InetSocketAddress) socket.getLocalSocketAddress();
}
 
Example 5
Project: https-github.com-apache-zookeeper   File: ClientCnxnSocketNIO.java   Source Code and License Vote up 4 votes
private void updateSocketAddresses() {
    Socket socket = ((SocketChannel) sockKey.channel()).socket();
    localSocketAddress = socket.getLocalSocketAddress();
    remoteSocketAddress = socket.getRemoteSocketAddress();
}