I’m working on a turn based multiplayer game. A match is between 2 players only. I know Photon Unity Networking doesn’t support peer-to-peer connection, but I was thinking about a work-around. The architecture I currently have in mind involves a central server providing the matchmaking and performing some additional tasks such as generating the map. The game it’s self will provide a server and a client on each device. One player’s client will communicate with the other’s server and vice-versa, without going through the central server. After the central server informs both clients of each other and gives them the map, they will “talk” directly to each other.
I such an architecture feasible or recommended in an Unity game? If not, why? What are it’s pro’s and cons? What would you recommend as an networking model for a 1vs1 turn based game?
I would not recommend this.
What do you gain from such an architecture?
Con: You have to implement direct connections, serialization of your messages, error handling (for connections) and you have to worry about NAT, etc.
Can’t you just use an authoritative server where the server resides on a players machine? This is sometimes called a “listen server”. Unity is pretty much built for exactly this kind of architecture, peer-to-peer in my (and tobiass’) opinion is just complicating things unnecessarily. I don’t see any reason for a peer-to-peer connection system in your description. 2 player turn based games are, generally speaking, the absolute simplest kind of networking games to create and don’t require that level of sophistication.
Just make one player the “server”, and the other the client, yet have the server code reside on the player’s machine. Unity can help with connecting players, NAT, etc.
EDIT: Woops, tobiass’ answer confused me, I misread. It sounds like you are in fact implementing a listen server (I think it was being accidentally called peer-to-peer). What you’re trying to implement is fairly standard in Unity, however to my knowledge not so much in Photon Cloud. If you’re set on Photon Cloud, I can’t help. I can suggest that Unity’s built in networking does this out of the box, using the MasterServer system.
Indeed, I am trying to implement a listen server. I remember reading about it somewhere and does seem to be the best thing for my purpose. As for Photon, I’m not hell bent on using it. However, I am not very sure how players will know about each other without first connecting to a central server. Are the built-in features of Unity sufficient for matchmaking?
Well… The new Unity Networking (in 5.1) is supposed to be able to handle matchmaking, etc. However, it is almost 100% broken as of now, and no ETA on when it will be fixed. The forum is filled with bug reports as it was released < 2 weeks ago. I can say from experience over the last week of playing with the new API that it is buggy beyond belief…
Old unity networking however (4.x) implements the MasterServer class, which is what you’re trying to do but already built for you. In essence, the MasterServer is a SQL database of sorts that acts as the “central server” you’re talking about, holding player host info such as IP addresses, etc. Unity supplies a server for free that runs the MasterServer, however it is generally said to be strictly for development and testing purposes (I’ve seen it go down a few times, myself). You can download the MasterServer and run it on your own server for use with real clients (http://unity3d.com/master-server).
You could use the Photon Cloud, then you don’t have to worry about hosting at all and the costs depend on your CCU. We have a 100 CCU “subscription” which doesn’t expire.
As 100 CCU doesn’t sound like much but you need quite a downloads to hit that limit. And you can scale your subscription on demand (even to lower CCUs) when your game is a hit.
Unity’s networking uses some Internet / Multiplayer service for matchmaking. It’s unclear if you can run one yourself (afaik) and there is no pricing known yet.