Continuing our journey of local multiplayer technologies, in this article we will see what are the considerations to make in order to implement local multiplayer on WiFi networks.
While now both Bluetooth and Multipeer Connectivity are viable options for implementing local multiplayer games, they both have a common disadvantage: You cannot have one player using an Android device connected to a player using an iOS device.
The solution to this problem is to implement WiFi networking, using open protocols that are recognized by both operating systems, so let's take a look at the technologies involved:
The first technology is of course TCP/IP, so a server would create a TCP socket, and the client would connect to that socket, but in order to do that, it must know both the IP address and the TCP port of the server.
In order to make the IP address and the TCP port known to all the devices on the network, the server can publish those information using a technology called Zeroconf (aka Bonjour).
Ok, now let's see how to implement those technologies using Cordova:
Let's start with the TCP sockets:
There exist the cordova-plugin-chrome-apps-sockets-tcpserver and cordova-plugin-chrome-apps-sockets-tcp plugins, but I prefer not to use them for 2 reasons:
- Chrome Apps for Mobile are no longer being actively developed
- I already had bad experiences with Chrome Apps for Mobile in the past (The bugginess of cordova-plugin-chrome-apps-bluetoothsocket is the very reason why I made cordova-plugin-networking-bluetooth)
But wait a minute: who said that we need raw TCP sockets?
Remember, a Cordova application is just a Web application, and the Web already has WebSockets, that can be used to handle the client side connection.
For the server side, all we need now is a WebSocket server for Cordova, and fortunately there is one: cordova-plugin-websocket-server by Becvert Prod.
Now let's move on to the Zeroconf part, and it turns out that there is the cordova-plugin-zeroconf, also by Becvert Prod.
By using these plugins you can implement a multi-platform multiplayer game, but it turns out that using correctly these technologies is much harder, and has much more implications than it may initially seem.
We are going to see these implications in the next blog post, so stay tuned.