| msgType | Message type number. |
| handler | Function handler which will be invoked for when this message type is received. |
Register a handler for a particular message type.
There are several system message types which you can add handlers for. You can also add your own message types.
import Networking;
function Start() { NetworkServer.Instance.Listen(7070); Debug.Log ("Registering server callbacks"); NetworkServer.Instance.RegisterHandler(MsgType.SYSTEM_CONNECT, OnConnected); }
function OnConnected(conn : NetworkConnection, reader : NetworkReader) { Debug.Log ("Client connected"); }
The system message types are listed below:
public class MsgType { static public short SYSTEM_CONNECT = 1; static public short SYSTEM_DISCONNECT = 2; static public short SYSTEM_OBJ_CREATE = 3; static public short SYSTEM_OBJ_DESTROY = 4; static public short SYSTEM_ERROR = 5; static public short SYSTEM_READY = 7; static public short SYSTEM_RPC = 8; static public short SYSTEM_OBJ_SPAWN = 9; static public short SYSTEM_UPDATE = 10; static public short SYSTEM_OWNER = 11; static public short SYSTEM_COMMAND = 12; static public short SYSTEM_COMMAND_SLOW = 13; static public short SYSTEM_RPC_SLOW = 14; }
Most of these messages are for internal use only. So users should not define message ids in this range. (NOTE: this should be enforced?)