Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / Peer to peer networking (I think??)

Author
Message
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 24th May 2020 01:26
I have a very very very basic understanding of networking so this question may seem very stupid.
Can i make this example of local comms work over the internet. (Not using a server)

Attachments

Login to view attachments
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 26th May 2020 23:55
Well this isn't Peer-to-Peer as you're using a Host-Client Approach...
For a Peer-to-Peer, what you want to do is setup a UDP Listener as that will basically monitor a specific Port; just use "anyip4" as the address.
This as a note will work for receiving packets, but you will need to setup a Handshake for each Connected Player in order to get their IP Address to Send Packets.

Doing this you can go "Server-less" but you'll need to create an "Address Book" so to speak for other Players., meaning you'll have to have some way of them communicating first.
There are two methods for this...

either
A • They manually share IPs and add them to their Address Book (like a Phone Number)
B • Create a Shared Website (anything that supports JavaScript, Active PHP, ASP will work), where when someone connects; it creates a Unique ID for them (which they use to "Sign In") then when they're Connected to the Site (say when your Game is running), it will in the background get their IP and share it with anyone on their Whitelist ("Friends"), which itself would be a list of UID.
In essence it would act as a Lightweight Host/Server (like how Xbox Live works., as strictly speaking your accounts are only on their Servers for Backup Purposes... the actual Accounts are shared via Peer-to-Peer and updated every 5 minutes for Data, and 1 Minute for Activity)

Most Free Hosts without Database are actually enough to do this, just provided they support Web 2.0 Features., like Asynchronous GET/POST without reloading the Webpage; but that said provided you don't mind your bandwidth/connections on said Host being thrashed you could always do it via Web 1.0
Remember what's happening is you're effectively using the Web Host as a "Telephone Board" to allow people to connect without sharing sensitive information directly., as such it can all be handled by the App in the Background; and even Automatically Adjust the Update Checks based upon current Load to keep within the available Connections your host provides. (which are fairly low on Free Hosts)

Still once that info is stored, you don't really need to use the Host again... instead you can just directly query the Player.

I'm shattered from work... but I'll throw something together in the morning (or maybe thursday when I'm off) to help you.
Of course in the meantime I'd recommend checking out the Code Snippets Forum., as a lot of the DBP Code (esp. UDP Peer-to-Peer, which I do recall making one) that should be more-or-less identical.
Would be a great starting point
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 27th May 2020 05:57
Awesome! Looking forward to it.
Thanks
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 29th Jun 2020 11:28 Edited at: 29th Jun 2020 11:29
Hi blink0k, Pixel Killers use peer to peer networking However, it does also rely on a server for punching through clients firewall, but after the punch through it is pure P2P. I can maybe scissor out some code for you?

EDIT: If you don't use punch through you need to have all clients set up port forwarding in their router (most likely).
13/0
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Jun 2020 11:36
That would be awesome! Thank you
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 29th Jun 2020 19:58
I will get on it tomorrow
13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 1st Jul 2020 10:25
Hi blink0k, I've been scissoring the code but it turns out it's a massive system that's poorly documented. You can still get the source if you'd like but I think it is easier if I explain what needs to be done, then you can design something that actually makes sense Again, you're more than welcome to get the source and ask all the questions you'd like Anyways:

You need a server, a cheap Ubuntu server will do fine. Then, in C++, (you can start with the included console app in Tier 2) you make a small console app with a UDP listener (here, most ports will usually be open on the server, pick a port in the above system range), this listener will read the port and IP of clients, and the clients need to know what other clients they want to connect to. You could make a list of games open for new players, the player/client pick a game, sends a message to the server with what game number they would like to join, then all clients connected to this game will receive a message with the new clients IP and port, the clients store the IP and port for further communication, and here is the important part: Now all the clients sends UDP packets to all other clients on the stored IPs and ports, this will let the firewall know that it can expect packets to come back from these IPs and ports.

Very short:
The server has all ports open, will listen for packets on UDP, and read IP and ports, it will give IP and port to other clients.
Clients have to send UDP packets to the IP and port of other clients to open firewall/NAT. Nothing will come back from other clients before they have done this. This might not work on some NAT, but this should mostly relate to enterprise NATs.

The reason why UDP is good for this is that it can send to IP and port without a handshake first, so they just fire the packet with no guarantee for arrival. I have then build my own system on top of that, which guarantees packet arrival.

If anything is unclear, do let me know!
13/0
Xaron
9
Years of Service
User Offline
Joined: 3rd May 2014
Location: Germany
Posted: 1st Jul 2020 10:57 Edited at: 1st Jul 2020 11:00
Hey Cybermind, that sounds great and I would be interested in that code as well, even if poorly documented.

Couldn't that be made even easier without setting up a full server? What about a simple php/mysql hosting solution where that "server" just receives all currently available player ip's and stores them so players could find each other?
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 1st Jul 2020 11:19
Possible, but the reason I use the server with AppGameKit UDP packets is that the listener can read what IP the packet comes from and what port the NAT assigned for the communication. The NAT assigned port is not always the same as port assigned in the app, this is especially true if other clients on the same network use the same port for something.
13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 1st Jul 2020 11:26
I will PM you guys when I have scissored all the code.
13/0
Xaron
9
Years of Service
User Offline
Joined: 3rd May 2014
Location: Germany
Posted: 1st Jul 2020 11:30
Quote: "The NAT assigned port is not always the same as port assigned in the app, this is especially true if other clients on the same network use the same port for something."


Aye, didn't think of that. And thank you!
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 1st Jul 2020 22:10
Thanks matey
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 2nd Jul 2020 09:21
Quote: "Quote: "The NAT assigned port is not always the same as port assigned in the app, this is especially true if other clients on the same network use the same port for something."


Aye, didn't think of that. And thank you! "


And even in the cases where the app port and NAT port are the same, NAT or Firewall will still not let data come in through this port, you have to send data out of that port to the IP you are going to receive data from.
13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 2nd Jul 2020 11:01
Hi guys, I've sent you part of the source, feel free to ask as many questions you'd like, I know it's hard to read but it works super for my game with low latency and guaranteed packet arrival. I kindly ask you don't share the source you've got from me, but I would be more than happy to help build a more readable universal version that could be shared
13/0
Xaron
9
Years of Service
User Offline
Joined: 3rd May 2014
Location: Germany
Posted: 3rd Jul 2020 06:51
Thank you, will look into it!

Login to post a reply

Server time is: 2024-04-19 23:53:30
Your offset time is: 2024-04-19 23:53:30