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.
Peer-to-Peer Networking Question
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- thebigredforest
- Prole
- Posts: 2
- Joined: Fri Feb 24, 2017 8:37 pm
- Contact:
Peer-to-Peer Networking Question
Last edited by thebigredforest on Sat Feb 25, 2017 1:49 am, edited 2 times in total.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Networking question
Use hamachi and enjoy the added lag.
Me and my stuff True 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.
- thebigredforest
- Prole
- Posts: 2
- Joined: Fri Feb 24, 2017 8:37 pm
- Contact:
Re: Peer-to-Peer Networking Question
There is a technique called "NAT punchthrough" but it requires an accessible server on the internet.
Re: Peer-to-Peer Networking Question
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?
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Peer-to-Peer Networking Question
I only found one relevant thread here on the forums.
Me and my stuff True 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.
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: Peer-to-Peer Networking Question
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)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Peer-to-Peer Networking Question
Which kind of requires that server. For most NAT types the following (udp!) method works:
- Magically obtain a server list (usually by having a master server where the game can say "Hi, I exist at <port>!")
- Send a message to some master server saying "I want to connect to <targetip>:<targetport> from <myport>"
- The master server forwards this via an established connection to the server, saying "Hey, <clientip>:<clientport> wants to connect"
- The client just starts sending traffic to the server, and vice versa
- At some point the intermediary NATs see bidirectional traffic, so "connect" the two ends, and they'll see each other's traffic.
- Now you've done the holepunching, connect as normal.
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.
Re: Peer-to-Peer Networking Question
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").
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").
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Peer-to-Peer Networking Question
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 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/
Right, as long as both sides know each other's details (accurately!) the hole punching works.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").
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.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 3 guests