Peer-to-Peer Networking Question

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
thebigredforest
Prole
Posts: 2
Joined: Fri Feb 24, 2017 8:37 pm
Contact:

Peer-to-Peer Networking Question

Post by thebigredforest »

I want to add peer to peer multiplayer to a game i'm working on, but I do not want to have people port forward their router, just to play my game. I am a complete noob when it comes to networking.
How should I accomplish this?

Thanks everyone!

Edit:
To further explain what I am looking for, the client will start server on their computer and then others can connect to it. Kinda like Call od Duty where there is one host, and many other clients.
Last edited by thebigredforest on Sat Feb 25, 2017 1:49 am, edited 2 times in total.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Networking question

Post by zorg »

Use hamachi and enjoy the added lag. :crazy:
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
thebigredforest
Prole
Posts: 2
Joined: Fri Feb 24, 2017 8:37 pm
Contact:

Re: Networking question

Post by thebigredforest »

Nice. I hate hamachi.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Peer-to-Peer Networking Question

Post by raidho36 »

There is a technique called "NAT punchthrough" but it requires an accessible server on the internet.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Peer-to-Peer Networking Question

Post by airstruck »

You should be able to do holepunching without an intermediary server if you have players exchange their ip addresses outside of the game. I thought someone around here had a holepunching library?
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Peer-to-Peer Networking Question

Post by zorg »

I only found one relevant thread here on the forums.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Peer-to-Peer Networking Question

Post by Positive07 »

If someone gets this right that person should MUST make a library out of it!!
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Peer-to-Peer Networking Question

Post by bartbes »

airstruck wrote: Sat Feb 25, 2017 3:22 am You should be able to do holepunching without an intermediary server if you have players exchange their ip addresses outside of the game.
Which kind of requires that server. For most NAT types the following (udp!) method works:
  1. Magically obtain a server list (usually by having a master server where the game can say "Hi, I exist at <port>!")
  2. Send a message to some master server saying "I want to connect to <targetip>:<targetport> from <myport>"
  3. The master server forwards this via an established connection to the server, saying "Hey, <clientip>:<clientport> wants to connect"
  4. The client just starts sending traffic to the server, and vice versa
  5. At some point the intermediary NATs see bidirectional traffic, so "connect" the two ends, and they'll see each other's traffic.
  6. Now you've done the holepunching, connect as normal.
Note that a peer behind a NAT can't determine their own ip nor their port. Most NATs will map the same internal source port to the same external source port for different destinations, though, so port 1234 will map to, for example, 2345 when sending traffic to 8.8.6.6, and to also to 2345 when sending traffic to 8.8.8.8 (these are examples, of course). This is why you want to register to the master server using the same socket that will accept the connections (which is perfectly possible with udp). You can use an additional socket for further notifications, if you want to, but again, using the same socket is pretty much the only way to figure out the ip and port. The same goes for the client, of course, it needs to use the same socket for both the master server and the other peer.

For NATs that do not re-use port mappings.. there's no practical way to holepunch. Also note that you might want to add rate limiting on your master server, or something of the sort, so people can't just send a bunch of connection requests via your server.

Lastly, if you're a fan of XML and complicated standards, you might be able to figure out UPnP and establish temporary port forwarding that way. I'm not sure how many routers you'll find that actually accept UPnP though, it may be (way) more effort than it's worth.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Peer-to-Peer Networking Question

Post by airstruck »

I'm sure I've seen it done without a master server, but I can't remember where. I may have been thinking of this: http://samy.pl/pwnat/

Of course if two players actually exchanged IPs (host has client's IP as well), you shouldn't need a master server either, and wouldn't need fancy tricks like pwnat. By "outside the game" I just meant by text message, phone call, shouting across the street, etc. Unclear whether that suits the OP's use case (looks like it from the title and first paragraph, but not the part after the "edit").
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Peer-to-Peer Networking Question

Post by bartbes »

airstruck wrote: Sat Feb 25, 2017 5:10 pm I'm sure I've seen it done without a master server, but I can't remember where. I may have been thinking of this: http://samy.pl/pwnat/
Though it does presume the client knows the server's public ip (and port?), which seems a bit weird.
airstruck wrote: Sat Feb 25, 2017 5:10 pm Of course if two players actually exchanged IPs (host has client's IP as well), you shouldn't need a master server either, and wouldn't need fancy tricks like pwnat. By "outside the game" I just meant by text message, phone call, shouting across the street, etc. Unclear whether that suits the OP's use case (looks like it from the title and first paragraph, but not the part after the "edit").
Right, as long as both sides know each other's details (accurately!) the hole punching works.

In practice, though, you'll want some server so you can have a server list anyway, so using that same server to help with holepunching isn't a problem.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests