Skip to content

Parsers

MessagePack Parser

By default the SocketManager uses a JSon parser and LitJson to encode/decode objects. It's also capable to send and receive MsgPack encoded messages if the server uses socket.io-msgpack-parser.

To enable and use it, follow these steps:

  1. Download and import the Json & MessagePack Serialization package
  2. Create a new Asembly Definition file under the Plugins\GameDevWare.Serialization folder
  3. Locate the com.tivadar.best.socketio.asmdef file under the com.tivadar.best.socketio\Runtime\ folder
  4. Reference the newly create asmdef file and press Apply:

    BestHTTP_AssemblyDefinition_MessagePackBestHTTP_AssemblyDefinition_MessagePack

  5. Add the BEST_SOCKETIO_ENABLE_GAMEDEVWARE_MESSAGEPACK define to the Scripting Define Symbols input under PlayerSettings/Other Settings:

    GameDevWare_MessagePack_ScriptingDefineSymbols.pngGameDevWare_MessagePack_ScriptingDefineSymbols.png

  6. Use the now available MsgPackParser class:

    var manager = new SocketManager(new Uri("http://localhost:3000"));
    manager.Parser = new MsgPackParser();
    

The MsgPackParser class can be found in the com.tivadar.best.socketio\Runtime\Parsers\ folder.

JSON.NET from Package

When Newtonsoft's JSON .NET For Unity is installed through the Package Manager window (or as a dependency of another package), the Best SocketIO package can detect it and automatically enables the JsonDotNetEncoder class.

var manager = new SocketManager(new Uri("https://localhost:3000/"), new JsonDotNetParser());

JSON.NET from the Asset Store

Another JSon parser using Newtonsoft's JSON .NET For Unity.

Steps to enable it and use it:

  1. Download and import the Newtonsoft's JSON .NET For Unity package.
  2. Add the BEST_SOCKETIO_ENABLE_NEWTONSOFT_JSON_DOTNET_ENCODER define to the Scripting Define Symbols input under PlayerSettings/Other Settings and press Apply:

    Scrypting Define SymbolsScrypting Define Symbols

  3. Use the now-available JsonDotNetEncoder class:

    var manager = new SocketManager(new Uri("https://localhost:3000/"), new JsonDotNetParser());
    

JsonDotNetParser class can be found in the com.tivadar.best.socketio\Runtime\Parsers\ folder.

Comments