PlayerIO

The fastest way to build online games without breaking a sweat.

Clientside Code for Multiplayer Service

Regardless of which client library you are using, ActionScript3, .NET Client, or the Unity3D Client, the principles and method names are the same.

All clients also have a DevelopmentServer property that you should set if you want your client to connect to your local development server instead of the live servers.

When a client wants to connect to a game server, it has to connect to an existing room. All rooms have a unique id, a type that corresponds to your serverside code, a visibility, and extra room data that you can supply when creating it and change from your serverside code.

Reference documentation

These methods are fully documented here:

Clients can be connected to any number of rooms simultaneously, and you use these methods to create, join, or list rooms:

  • CreateRoom()
  • JoinRoom()
  • ListRooms()
  • CreateJoinRoom()

When a client is connected to a room, there are also methods for sending and receiving Messages. Clients can disconnect from rooms at any time, but you can also disconnect clients from your serverside code, for example if you want to allow players being kicked out of a game.

Create Room

Creating a room is pretty straight-forward, you just need to call the CreateRoom method with the appropriate arguments.

If you don't supply your own room id, a random id will be generated for you by the server.


Room Data

The room data can be supplied when you create a room from a client, and in your serverside code you can both read and modify this data through the RoomData property.

Typically you should use room data to allow players to customize a specific game, for example by selecting a specific map, or deciding how many max players there can be.

The room data is also available when you list rooms, so if you build some sort of lobby system, you can display the settings of already created rooms that are waiting for players to join.

List Rooms

After various clients have created rooms you can list those rooms and search among them with the ListRooms method. You have to specify a roomtype, and you will only get back rooms that are currently visible.

It is recommended that you use the resultLimit and resultOffset arguments to implement a paging system so that you don't list all existing rooms all the time.

You can also use the searchCriteria argument to filter the room list based on the roomData properties of the rooms. However, to use this feature you must first define which properties are searchable under the Settings tab of the Multiplayer Control Panel for your game. Below is an example that lists only rooms where the maxplayers property is set to 4, and only lists the 20 first rooms:

Join Room

To make a player join a room, simply call the JoinRoom method. The only required argument to this method is the id of the room to join, and the given room of course has to exist for this method to succeed.

When a player is joining a room, the server will first perform a check by running the AllowUserJoin method. If you override this in your serverside code you can conditionally allow the user to join or not.

Create and Join Room

Finally there's a convenience method that allows you to create and join a room at the same time that is simply called CreateJoinRoom. If the room already exists, the player will join the room directly, and if it doesn't exist, it will be created with.

This method takes the same arguments as CreateRoom and JoinRoom does separately, and you can omit the room id to get one generated for you just like in the regular method.

Service Rooms

If you supply $service-room$ as the id the player will join a special service room.

Service rooms have random names, and as soon as a room is 75% full, a new room will be created and new players that join will go to that room instead, thus ensuring that a minimum of these rooms are created and that players are balanced evenly into them.

This type of room is very useful when it's important that your players have a connection to a room, but when it doesn't really matter which other players are in this room. That rooms won't fill up completely also means that you can move players around the rooms if you want two specific players to exchange messages. This feature makes it really easy to build a distributed lobby system or matchmaking system, for example.