Reputation: 21
In simple socket programming in java , what ip should be given while making new socket and its on wan
//Server side
ServerSocket ss = new ServerSocket(8888);
System.out.println("\n\n\tWaiting for connection\n");
Socket c = ss.accept();
System.out.println("\n\n\tConnection established\n");
//Client side
Socket c=new Socket("192.16*****",8888);
System.out.println("\n\n\tSuccessfully connected to the server");
//in **** there is complete ip address of my computer .... i.e. IPV4 address (checked
//from ipconfig command on cmd)
Upvotes: 2
Views: 181
Reputation: 320
By default, a new ServerSocket
should bind to all network interfaces.
You should be able to find out what interfaces are being used by running (I assume you're running Windows, since you mentioned ipconfig):
netstat -an |find /i "8888"
If in fact the application is creating a socket and binding to all interfaces, you should see an entry like the following:
TCP 0.0.0.0:8888 0.0.0.0:0 LISTENING
Otherwise, you should be able to get the interface that is being used (it's the first IP address from the left).
Upvotes: 1