Legacy Documentation: Version 5.1
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

NetworkClient.SendByChannel<MSG>(short,MSG,int)

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Parameters

id Message type ID number.
msg Message structure.
channelId Channel to use for sending.

Returns

void True if message is sent.

Description

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); } }