本文整理匯總了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();
}