5Mixer / mphx

A little library to let you make multiplayer games easily with Haxe. No longer maintained and better options are available.
MIT License
125 stars 16 forks source link

P2P multiplayer game? #27

Closed Danni06 closed 8 years ago

Danni06 commented 8 years ago

Hello, nice work with the library. I have a question, is possible to create a P2P multiplayer game with this library?

5Mixer commented 8 years ago

Thanks for the question! Peer to peer is not currently built into the library, no. I don't think it ever will be either. It's not impossible to make a peer to peer like system using MPHX, by making each client a server, but that is not too desirable, as you'll end up with much more lag, and a lot of overhead for each connection.

I'm curious as to why you wish to use P2P though. If it's because you don't with to host an external server, there are ways around that using a typical Client-Server architecture. Just setup one player as being the server and a client, and then each player connects to them. Obviously the server device has to be able to run on any devices, and you won't be allowed beyond a firewall, but the same is true for peer to peer. If this seems difficult, feel free to ask for help.

Peer to peer is not nearly as common as client server architectures these days.

I look forward to your response.

Danni06 commented 8 years ago

I'll wish to use P2P because i want use it on mobile platform(android) and I want to use one device as both types: client and server, this device manage the connections and others actions of the other devices connected to him, but also it act as a client too. In other platforms typical Client-Server architecture is good. Do you suggest to me any idea that will do want I want? Sorry for my bad english.

I look forward to your response :)

5Mixer commented 8 years ago

Cool, what you are describing is entirely possible. There is a game on the app story called Flappy Golf that does this (but with Bluetooth).

I think it will be quite simple to make it work. The first device starts a server, because 'new game' is clicked. Then others join the game, and the game begins.

The main issue I think you will have is telling other connections that a game exists, and is joinable. Normally a client needs an IP to connect to the server. The simplest option is the server device shows an IP, and others type it in, but telling gamers to type in IP's doesn't sound amazing.

You could do it anyway you wanted though - You could even send the IP over Bluetooth.

Once the connection/IP is established, it's simpler. The server device can talk straight to the server events, without even touching the net. Just go straight to the event manager, rather than .send().

Doing this won't be super easy, it will take work to make the server device go straight to the event manager, and work out how other players will get the servers IP.

How do you feel about players typing in an IP?

On 28 Apr 2016, at 8:51 pm, Danni06 notifications@github.com wrote:

I'll wish to use P2P because i want use it on moblie platform(android) and i want to use one device as both types: client and server, this device manage the conexions and others actions of others devices connected to him, but also it act as a client too; and the others devices as clients. In other platforms typical Client-Server architecture is good. Do you suggest to me any idea to do that i want to do? Sorry for my bad english.

I look forward to your response :)

— You are receiving this because you commented. Reply to this email directly or view it on GitHub

Danni06 commented 8 years ago

I think the problem of the IP is easy to solve, because I want to do the connection over Wi-FI, the server/client device will be an access point, and the other clients will connect to him. Is it possible if the server creates a local network over wifi with the 192.168.0.1 IP for example, in the code of the game, write the default connection ip was 192.168.0.1?

5Mixer commented 8 years ago

Hmm, from what I understand, you are assuming that the IP of the server will be 192.168.0.1, but if it is hosted by a device, the IP will be what's called a local IP. So each device on a WiFi network has a local IP, which looks like 10.0.0.x. The router has an IP that looks like the one you mentioned. Because the server device is connecting to a router, it is not a router itself, it will have an IP like 10.0.0.7, which the other devices will need to connect to.

This local IP does not really have a 'default', so it cannot be presumed.

In my humble opinion, I think that your primary focus should be on making a multiplayer game, and not worrying about IP's and stuff yet. The main bulk of making a multiplayer game will be spending time making each client sync up.

I hope that clears up a few things.

On 28 Apr 2016, at 9:26 pm, Danni06 notifications@github.com wrote:

I think the problem of the IP is easy to solve, becasue i want to do the conexion over Wi-FI, the server/client device will be an acces point, and the other clients will connect to him, is it possible if the server creates a local network over wifi with the 192.168.0.1 IP for example, in the code of the game, write the default connection ip was 192.168.0.1?

— You are receiving this because you commented. Reply to this email directly or view it on GitHub

5Mixer commented 8 years ago

Closing this because this library does not support true P2P, and I don't see it being implemented any time soon, due to the nature of the library and it's platform support.

P2P can be emulated though, with one client volunteering to act as a server as well as a client.