id | Message type ID number. |
msg | Message structure. |
channelId | Channel to use for sending. |
void True if message is sent.
Send a message structure through the given channel.
The channel should be configured with the tuner in Configure.
#pragma strict public class MyMsgTypes { public static var MSG_LOGIN: short = 51; public static var MSG_START: short = 52; } public class LoginMessage extends System.ValueType { public var myName: String; } class GameClient { var myClient: NetworkClient; GameClient { myClient = new NetworkClient(); myClient.Connect("localhost", 55555); myClient.RegisterHandler(MsgType.SYSTEM_CONNECT, OnConnected); } public function OnConnected(conn: NetworkConnection, reader: NetworkReader) { myClient.Ready(); var msg: LoginMessage; msg.myName = "SomeGuy"; myClient.SendByChannel(MyMsgTypes.MSG_LOGIN, msg, 0); } }
using UnityEngine; using UnityEngine.Networking;
public class MyMsgTypes { public static short MSG_LOGIN = 51; public static short MSG_START = 52; };
public struct LoginMessage { public string myName; }
class GameClient { NetworkClient myClient;
GameClient() { myClient = new NetworkClient(); myClient.Connect("localhost", 55555);
myClient.RegisterHandler(MsgType.SYSTEM_CONNECT, OnConnected); }
public void OnConnected(NetworkConnection conn, NetworkReader reader) { myClient.Ready();
LoginMessage msg; msg.myName = "SomeGuy";
myClient.SendByChannel(MyMsgTypes.MSG_LOGIN, msg, 0); } }