Well it seems I never did a post on my Tic Tac Toe game so now would appear to be as good as time as any to do a little write up about it, explain the reason behind it and some of the things I ran into while creating Multiplayer Tic Tac Toe!
I originally picked Tic Tac Toe as my base game as I dove head first into multiplayer coding. Its just about as simple as a game can get and wouldn’t require too much game code as opposed to the multiplayer code required to get things working across networks and devices. During this time I spent months researching all the different architectures, methods and solutions people were using out there from third party addons like Photon, Node.JS, Mirror, Litenet, etc to the integrated Unity UNet solution. I did as much research on each of them as any sane person could tolerate, looked at examples, tested demos and attempted to write basic chat programs with some. In the end I just chose to use Unitys UNet. It was easy to understand and easy to implement. Of course this was after a lot of trial and error.
The main basis for multiplayer is that you have multiple devices sending and receiving messages to each other. The base for my network was how these devices would interpret the messages and act accordingly. One of the first hurdles I ran into was while looking into peer to peer networking. There are quite a lot of issues with this structure which can grow depending on which devices your setting up the network on. With mobile phones, based on what I remember (This was over a year ago (I think)), mobile phones have a tough time hosting games while computers have a hard time punching through the router to host games and allow people outside the network to join. While some of the available network solutions had answers for these kinds of situations, I opted for a simpler remedy, its a called a relay server.
Most big multiplayer networks like Steam for example, will push players onto their relay servers when they can’t get around router issues, from what I read anyways. This was the perfect answer for my situation, especially since I was looking at creating simple turn based card or board games. The downside to this, for me anyways, is that it required a hosted server that I could use to run the relay server on, outside of my home network to make it easier for people to play against each other.
Ultimately I succeeded in writing my relay server that could handle people hosting tic tac toe games or joining tic tac toe games. I ran into a few issues with allowing people to log in in order to save stats, a logged in player playing against a non logged in player, registering players and quite a few other things that needed ironing out. In the end, I was very happy with the overall structure of my multiplayer network.
A bit after I finished the Multiplayer Tic Tac Toe game and my Relay Server, quite a bit after actually, unity decided to trash the UNet and make it obsolete. I said of course they did, thats just because I decided to use it! They are promising a new type of integrated networking system but after they trashed what they already had which I used, why would I use another network system they create? What if they decided to trash that one in the end too?
Here I was again, looking over all the different networking systems I could use. This meant having to port my existing Relay Server and Multiplayer Tic Tac Toe game over to the new library. In the end I decided to go with LiteNetLib due to how light weight it is, how easy it is to understand and how quick it was to implement. Of course my completion of the port is still a work in progress, but once I can get back to being focused on it, I will update this post!
Thanks for reading and if you have any questions, please leave a comment below!