/// <summary> /// 发送消息 /// </summary> /// <param name="opCode">操作码</param> /// <param name="subCode">子操作码</param> /// <param name="value">参数</param> public void SendMsg(int opCode, int subCode, object value) { Console.WriteLine("--发送消息--" + opCode + " " + subCode); msg.change(opCode, subCode, value); byte[] data = EncodeTool.EncodeMsg(msg); byte[] packet = EncodeTool.EncodePacket(data); SendMsg(packet); }
/// <summary> /// 处理数据 /// </summary> private void ProcessData() { isProcessingReceive = true; //解析包,从缓存区里取出一个完整的包 byte[] packet = EncodeTool.DecodePacket(ref cache); if (packet == null) { isProcessingReceive = false; return; } NetMsg msg = EncodeTool.DecodeMsg(packet); if (receiveCompleted != null) { receiveCompleted(this, msg); } ProcessData(); }