ZeeJ
ZeeJ

Reputation: 23

How does one connect with another machine with IP address?

So I've been learning Java Sockets for some time now, and all my codes are tested basically with a localhost (my own computer).

I was wondering if say I have another machine in another country, does the simple client-server connection still work? (My codes are peer-to-peer connection).

Is it that simple with just IP address and Port?

Sorry this question seems weird but back in the days when I was playing online games, simply putting "connect 'ip address' " didn't always work.

Upvotes: 0

Views: 821

Answers (1)

Stephen C
Stephen C

Reputation: 718718

I was wondering if say I have another machine in another country, does the simple client-server connection still work?

Possibly yes, possibly no.

Is it that simple with just IP address and Port?

Possibly yes, possibly no.

If the IP address is a public IP address, AND there are no firewall issues, then it should work. But that is a BIG IF ......

  • If the remote IP address you are trying to connect to is not a public IP address, then there is no way that packets can be routed to it. No connection is possible.

  • If there are firewalls between your machine and the remote IP, they need to let packet for that IP / protocol / port through, otherwise connections will fail.

IMO, you would be better off doing some basic research / reading on how IP-based networking works before you ask questions like this.


(My codes are peer-to-peer connection).

That is at the next level up the networking stack. Peer-to-peer is implemented on top of transport-level protocols like TCP/IP and UDP/IP. If the transport level doesn't work, then application level protocols won't either.

Upvotes: 3

Related Questions