Skip to content
Advertisement

Java socket only use loopback

I have tried to connect my laptop to another laptop (on the same network, both using Windows 10) using java socket.

Here is the client code :

JavaScript

And the server code :

JavaScript

But for some reason, even if I specify an ip address, the laptop only look for a host in loopack, not on the private network. Here is the proof :

Loopback traffic (wireshark)

Wi-fi traffic (wireshark)

I also added a rule to the firewall of both laptop to accept tcp incoming and outgoing on the port 50065.

So is there a way to parameterize the socket to use the right network interface (the one using the private network) or am I missing something here ?

Advertisement

Answer

First, check if you are able to ping one laptop from another. If yes then try below.

The Address field contains the base address that this listen socket is listening on. It contains the IP address and the port number.

If your listen socket listens on all IP addresses for the machine, the IP part of the address is 0.0.0.0.

Try to bind on your local IP or on any address using “0.0.0.0”

JavaScript
Advertisement