本文整理汇总了Java中java.net.Socket.getLocalSocketAddress方法的典型用法代码示例。如果您正苦于以下问题:Java Socket.getLocalSocketAddress方法的具体用法?Java Socket.getLocalSocketAddress怎么用?Java Socket.getLocalSocketAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.Socket
的用法示例。
在下文中一共展示了Socket.getLocalSocketAddress方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toString
import java.net.Socket; //导入方法依赖的package包/类
@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]";
}
}
示例2: getAddress
import java.net.Socket; //导入方法依赖的package包/类
@Override
public InetSocketAddress
getAddress()
{
SocketChannel channel = ep.getSocketChannel();
if ( channel != null ){
Socket socket = channel.socket();
if ( socket != null ){
return((InetSocketAddress)socket.getLocalSocketAddress());
}
}
return( null );
}
示例3: getLocalAddress
import java.net.Socket; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public InetSocketAddress getLocalAddress() {
if (channel == null) {
return null;
}
Socket socket = getSocket();
if (socket == null) {
return null;
}
return (InetSocketAddress) socket.getLocalSocketAddress();
}
示例4: updateSocketAddresses
import java.net.Socket; //导入方法依赖的package包/类
private void updateSocketAddresses() {
Socket socket = ((SocketChannel) sockKey.channel()).socket();
localSocketAddress = socket.getLocalSocketAddress();
remoteSocketAddress = socket.getRemoteSocketAddress();
}