SocketChannel 建立后,如何获取对方的PORT ?
private ServerSocketChannel m_server;
SocketChannel sc = m_server.accept(); //Accept a new socket client
TCP 连接,accept成功之后,如何获取对方的port --------------------编程问答-------------------- 谢谢各位了。 --------------------编程问答--------------------
SocketChannel sc = ....--------------------编程问答-------------------- sc.socket().getPort() api都指出了。
Socket socket = sc.socket();
System.out.println( "Client Port: " + socket.getPort() );
getPort():Returns the remote port number to which this socket is connected.
补充:Java , Java SE