本文整理了Java中java.net.Socket.getLocalPort()
方法的一些代码示例,展示了Socket.getLocalPort()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Socket.getLocalPort()
方法的具体详情如下:
包路径:java.net.Socket
类名称:Socket
方法名:getLocalPort
[英]Returns the local port this socket is bound to, or -1 if the socket is unbound.
[中]返回此套接字绑定到的本地端口,如果套接字未绑定,则返回-1。
代码示例来源:origin: aws/aws-sdk-java
@Override
public int getLocalPort() {
return sock.getLocalPort();
}
代码示例来源:origin: robovm/robovm
public int getLocalPort() {
if (this.socket != null) {
return this.socket.getLocalPort();
} else {
return -1;
}
}
代码示例来源:origin: robovm/robovm
public int getLocalPort() {
if (this.socket != null) {
return this.socket.getLocalPort();
} else {
return -1;
}
}
代码示例来源:origin: apache/geode
/**
* @return the local port of our {@link #socket}
*/
protected int getLocalPort() {
return this.socket.getLocalPort();
}
代码示例来源:origin: hierynomus/sshj
public int getLocalPort() {
return socket.getLocalPort();
}
代码示例来源:origin: pentaho/pentaho-kettle
private static int getUnusedPort() throws IOException {
Socket s = new Socket();
s.bind( (SocketAddress) null );
int var1;
try {
var1 = s.getLocalPort();
} finally {
s.close();
}
return var1;
}
代码示例来源:origin: apache/zookeeper
/**
* See {@link Socket#getLocalPort()}. Calling this method does not trigger mode detection.
*/
@Override
public int getLocalPort() {
return getSocketAllowUnknownMode().getLocalPort();
}
代码示例来源:origin: apache/activemq
/**
* @return pretty print of 'this'
*/
@Override
public String toString() {
return "" + (socket.isConnected() ? "tcp://" + socket.getInetAddress() + ":" + socket.getPort() + "@" + socket.getLocalPort()
: (localLocation != null ? localLocation : remoteLocation)) ;
}
代码示例来源:origin: wildfly/wildfly
protected String getSockAddress() {
StringBuilder sb=new StringBuilder();
if(sock != null) {
sb.append(sock.getLocalAddress().getHostAddress()).append(':').append(sock.getLocalPort());
sb.append(" - ").append(sock.getInetAddress().getHostAddress()).append(':').append(sock.getPort());
}
return sb.toString();
}
代码示例来源:origin: square/okhttp
int localPort = socket.getLocalPort();
代码示例来源:origin: alibaba/cobar
public boolean finishConnect() throws IOException {
if (channel.isConnectionPending()) {
channel.finishConnect();
localPort = channel.socket().getLocalPort();
isFinishConnect = true;
return true;
} else {
return false;
}
}
代码示例来源:origin: alibaba/cobar
public FrontendConnection(SocketChannel channel) {
super(channel);
Socket socket = channel.socket();
this.host = socket.getInetAddress().getHostAddress();
this.port = socket.getPort();
this.localPort = socket.getLocalPort();
this.handler = new FrontendAuthenticator(this);
}
代码示例来源:origin: wildfly/wildfly
public SocketAddress getLocalAddress() {
final Socket socket = conduit.getSocketChannel().socket();
return new InetSocketAddress(socket.getLocalAddress(), socket.getLocalPort());
}
代码示例来源:origin: robovm/robovm
/**
* Returns the local address and port of this socket as a SocketAddress or
* null if the socket is unbound. This is useful on multihomed
* hosts.
*/
public SocketAddress getLocalSocketAddress() {
if (!isBound()) {
return null;
}
return new InetSocketAddress(getLocalAddress(), getLocalPort());
}
代码示例来源:origin: wildfly/wildfly
@ManagedAttribute(description="The actual client_bind_port")
public int getClientBindPortActual() {return ping_sock != null? ping_sock.getLocalPort() : 0;}
代码示例来源:origin: apache/kafka
private String id(SocketChannel channel) {
return channel.socket().getLocalAddress().getHostAddress() + ":" + channel.socket().getLocalPort() + "-" +
channel.socket().getInetAddress().getHostAddress() + ":" + channel.socket().getPort();
}
代码示例来源:origin: wildfly/wildfly
public String toString() {
Socket tmp_sock=sock;
if(tmp_sock == null)
return "<null socket>";
InetAddress local=tmp_sock.getLocalAddress(), remote=tmp_sock.getInetAddress();
String local_str=local != null? Util.shortName(local) : "<null>";
String remote_str=remote != null? Util.shortName(remote) : "<null>";
return String.format("%s:%s --> %s:%s (%d secs old) [%s] [recv_buf=%d]",
local_str, tmp_sock.getLocalPort(), remote_str, tmp_sock.getPort(),
TimeUnit.SECONDS.convert(getTimestamp() - last_access, TimeUnit.NANOSECONDS),
status(), receiver != null? receiver.bufferSize() : 0);
}
代码示例来源:origin: jphp-group/jphp
@Signature
public Memory getLocalPort(Environment env, Memory... args) {
return LongMemory.valueOf(socket.getLocalPort());
}
代码示例来源:origin: wildfly/wildfly
public Connection(Socket sock) throws Exception {
this.sock=sock;
peer_addr=new IpAddress((InetSocketAddress)sock.getRemoteSocketAddress());
in=new DataInputStream(createBufferedInputStream(sock.getInputStream()));
out=new DataOutputStream(createBufferedOutputStream(sock.getOutputStream()));
runner=new Runner(new DefaultThreadFactory("tcp", false, true),
"conn-" + sock.getLocalPort(), this, null);
}
代码示例来源:origin: alibaba/canal
return new InetSocketAddress(channel.socket().getLocalAddress(), channel.socket().getLocalPort());
} catch (IOException e) {
throw new CanalClientException(e);
内容来源于网络,如有侵权,请联系作者删除!