3
\$\begingroup\$

We are making a 2 player game, using a Client/Server architecture and need a way to connect over the internet.

Connecting in the same network is no problem and works flawlessly. Will it be a lot of work to implement a way to connect online, that players can use (so nothing where they need access to the router settings)? And how would it be done?

I couldn't find a single tutorial or thread talking about this. They all just connected to the localhost.

(using gamemaker studio 2 and it's built in tcp networking functions)

edit:

The server regularly sends broadcast packages to all ip's, while the client reads their origin ip and can then connect to said ip. They both are on the same subnet so the adrress is 192.168.0.xx.

I also have a way to get the public ip (95.xxx.xxx.xx) using a http get from ipv4bot.whatismyipaddress.com. But when trying to connect to the server, using the public one, I't won't connect (doesn't matter if both are on the same network).

\$\endgroup\$
10
  • \$\begingroup\$ you should be able to find it under NAT punching \$\endgroup\$ – ratchet freak Feb 7 '19 at 17:06
  • \$\begingroup\$ @ratchetfreak Can't seem to find anything about NAT punching on google. Do you mean UDP holepunching? If not it would be awesome if you could provide a link to what you mean. \$\endgroup\$ – Lerrrtaste Feb 7 '19 at 17:10
  • \$\begingroup\$ When you say "Connecting in the same network is no problem and works flawlessly", do you mean that you can successfully make a connection of 2 users with each other and let them play the game as long as they are in the same network? \$\endgroup\$ – TomTsagk Feb 7 '19 at 18:01
  • \$\begingroup\$ @TomTsagk yes, exactly. The server sends a broadcast package to all ip addresses, while the client listens with a udp socket to get all servers/hosts in the network. The client can then connect using the ip adrress the broadcast was from. From there on only tcp is used. The devices are on the same subnet, so their addresses are 192.168.0.xx. \$\endgroup\$ – Lerrrtaste Feb 7 '19 at 18:46
  • \$\begingroup\$ Obviously the broadcast method doesn't work across the whole Internet, so how would you like users to locate one another instead? \$\endgroup\$ – DMGregory Feb 8 '19 at 0:18
1
\$\begingroup\$

It is not possible for two computers, each behind a firewall, to directly connect to each other. Not without some kind of intermediary that's outside, or by opening up the firewall to outside connections that get routed to an internal host. This is like LAN 101 security that you don't allow directly connections inside your LAN. You let connections come out, but not in.

It is possible if the computer acting as the server opens up their firewall to allow external connections, but this is both challenging for some game players to set up, and also insecure for the player's home network.

What you need is something to act as a broker between the two players. Both machines connect outside, to a mutually agreed server. That server then acts as the broker for the communications to share what one sends, and have it be received by the other. Something outside their firewalls needs to manage the connection between them. There is really no way around this.

I would suggest using XMPP (also known as Jabber) as the protocol and method to communicate between the players. It is an open messaging protocol that works over TC/IP that will let you pass messages between two systems using an intermediary server. You can read more about XMPP at https://xmpp.org/

There are a number of public servers for it that can work as the intermediary, which you can find at https://list.jabber.at/ Using a public server, you can get around not having an active server of your own.

Basically both of your game clients will use the XMPP server just like they were two clients using chat, but will send data packets to each other.

There is an assumption here that you don't need to send a massive amount of data, and that you trust both clients to not cheat, since you will have no traditional centralized server that is the arbitrator of game actions.

\$\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.