/// <summary> /// 丢失链接 /// </summary> void OnDisconnected(RazDisType dis, string msg) { Close(); //关掉客户端链接 int protocal = dis == RazDisType.Exception ? LuaProtocal.Exception : LuaProtocal.Disconnect; RazByteBuffer buffer = new RazByteBuffer(); buffer.WriteShort((ushort)protocal); RazNetworkManager.AddEvent(protocal, buffer); Debug.LogError("Connection was closed by the server:>" + msg + " Distype:>" + dis); }
/// <summary> /// 接收到消息 /// </summary> /// <param name="ms"></param> void OnReceivedMessage(int size, MemoryStream ms) { BinaryReader r = new BinaryReader(ms); byte[] message = r.ReadBytes((int)(ms.Length)); RazByteBuffer buffer = new RazByteBuffer(message); int pid = RazConverter.GetBigEndian_Int32(buffer.ReadInt()); int ctxId = RazConverter.GetBigEndian_Int32(buffer.ReadInt()); buffer.SetSize(size); buffer.SetPid(pid); buffer.SetCtxId(ctxId); RazNetworkManager.AddEvent(pid, buffer); }
/// <summary> /// 连接上服务器 /// </summary> void OnConnect(IAsyncResult asr) { outStream = client.GetStream(); client.GetStream().BeginRead(byteBuffer, 0, MAX_READ, new AsyncCallback(OnRead), null); RazNetworkManager.AddEvent(LuaProtocal.Connect, new RazByteBuffer()); }