Beginner’s Guide to Boardgame.io (Part 3): Remote Multiplayer
In my previous article, I walked through how to set up local multiplayer for the boardgame.io framework. Now I will walk through how to set up remote multiplayer.
Remote multiplayer is a different beast in boardgame.io because it is not just a toggled setting like local multiplayer was. To set up remote multiplayer, you must also set up a boardgame.io server.
Setting Up The Server
To set up the server, make a server.js file in your src folder. Then, use this code as a basis to set up your server.
Replace the TicTacToe game file with whatever game you are currently setting up with boardgame.io. This will set up the server to host your board game.
Running the Server
To run the server, you will first need esm installed, which will allow you to run ECMAScript modules. You can install esm using npm:
npm install --save esm
You can then run the server using the following command:
node -r esm src/server.js
Setting Up Multiplayer on the Boardgame.io Client
Then, you must set up the boardgame.io client, as shown in the local multiplayer guide.
First, you import SocketIo from boardgame.io’s repo. Then, with the multiplayer key, you set up a SocketIO server pointing at the server you have set up in the instructions above.
Conclusion
These steps will allow you to set up a boardgame.io remote multiplayer game. As such, you will be able to open multiple browser windows to access the app, and make moves in the boardgame.io framework from different ids/users. Boardgame.io has really done a lot of the work here and has abstracted away a lot of networking that you would otherwise have to deal with.