0
\$\begingroup\$

So I am trying to write server code for my game, and I am kinda running in a wall. I have seen oracles example for a server and client, but how do I allow it to connect to computers outside my network? Pretty much I'm trying to do the following

Client presses a key to move 1 unit to the left, the server receives the Client's input, checks if any modification is made, if there is send Client back to where they started.

The problem I have is how do I connect a Server and Client on separate internet connections?

\$\endgroup\$
1
\$\begingroup\$

The big problem of P2P connections is the NAT mechanism:

A gammer PC is probably before a router that use NAT technology, that is, the IP for Internet is not the same that he IP the PC have (local network). NAT change the connection port to work, so listening is not possible.

Solutions:

  1. The user need to configure a PORT forwarding, like for emule and other similar software.
  2. Any connection is done against a server that does not use NAT, but that is not P2P but client-server.

Connecting to a local server or any one in Internet is the same: you need the IP and the Port of the listenning server, connect to it/send or receive data/close connetion.

\$\endgroup\$
  • \$\begingroup\$ So your saying if I set the Host IP on the client to my outside IP Address, then route the info through my router to my PC via port forwarding? \$\endgroup\$ – Loligans Oct 3 '13 at 18:08
  • \$\begingroup\$ yes this is what you should try \$\endgroup\$ – Thomas Oct 4 '13 at 8:02
0
\$\begingroup\$

You're going to need to know the IP address of the server and use that as the "host" in your client. Just web-search "what's my IP" from the computer running the server and you can get it.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.