Loren Kuich
Loren Kuich

Reputation: 603

Sockets - Connect two computers on the same network with no port forwarding?

I am very confused. I cannot find a specific answer to my conundrum. I figured this applies to all languages, but I'm writing my application in Java specifically.

So, I am simply trying to connect two separate computers, which are running on the SAME network.

Computer 'A' is the server, and Computer 'B' is the client.

When the Client connects, I just want to display a message on the server.

My question: Is it possible to connect two PC's (one being the server, the other being the client), on the same network, without any kind of port forwarding, or other internet settings (with the exception of some firewall settings)? Also, what IP do you have to use to connect the two PC's?

Thank you very much!

Upvotes: 2

Views: 7846

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533820

You don't need port forwarding. All you need to do on the server is something like

ServerSocket ss = new ServerSocket(KNOWN_PORT);
while(running) {
    executor.submit(new SocketHandler(ss.accept()));

On the client side

Socket s = new Socket(KNOWN_HOST, KNOWN_PORT);

Upvotes: 2

Related Questions