2
如何從本地主機獲取套接字conncet的IP?從套接字獲取IP從本地主機連接到java
我試試這個:
ServerSocket ss = new ServerSocket(1919);
Socket test,s = new Socket("127.0.0.1",1919);
test=ss.accept();
System.out.println("we connect ");
InetAddress IP=test.getInetAddress();
System.out.println("IP of my system is := "+IP.getHostAddress()+"----"+IP);
了出來放:
IP of my system is := 127.0.0.1----/127.0.0.1
,但我需要: IP:192.168.0.XXX
thanxx
看一看:[在java TCP連接中綁定一個接口](https://stackoverflow.com/questions/11470459/bind-an-interface-in-java-tcp-connection),你可以綁定一個socket與任何活動界面。 – Boubakr