private void ReceiveBodyCallback(IAsyncResult ar) { try { OnInfo("--------------------start ReceiveBodyCallback"); if (!this.socket.Connected) { return; } int count = this.socket.EndReceive(ar); if (count == 0) { OnError("ReceiveBodyCallback:socket receive 0"); return; } this.readBytes += count; if (this.readBytes < this.bodyBuf.Length) { this.BeginReceiveBody(this.readBytes); return; } byte[] bytes_cmdid = new byte[2]; byte[] bytes_seq = new byte[4]; byte[] bytes_body = new byte[bodyBuf.Length - 6]; ByteAr_b.PickBytes(this.bodyBuf, bytes_cmdid.Length, bytes_cmdid, 0); ByteAr_b.PickBytes(this.bodyBuf, bytes_seq.Length, bytes_seq, 2); ByteAr_b.PickBytes(this.bodyBuf, bytes_body.Length, bytes_body, bytes_cmdid.Length + bytes_seq.Length); if (ByteAr_b.b2us(bytes_cmdid) == 0xa10b) { PswCode = ByteAr_b.b2i(bytes_body); } else { this.OnReceived(this.bodyBuf); /* Pt pt = ptMng.GetInstance().MakePt(ByteAr_b.b2us(bytes_cmdid),ByteAr_b.b2ui(bytes_seq), bytes_body); * * if (pt == null) * OnError("Receive unknow pt pt_id = " + ByteAr_b.b2us(bytes_cmdid)); * else * { * pt.seq = ByteAr_b.b2ui(bytes_seq); * this.OnReceived(pt); * }*/ } this.BeginReceiveHeader(0); } catch (Exception e) { OnError("ReceiveBodyCallback:socket catch" + e.Message); } }
public static void Update() { if (unHandMsgList != null) { while (unHandMsgList.Count > 0) { Pt pt = null; if (unHandMsgList.Count > 0) { lock (unHandMsgList) { byte[] bts = unHandMsgList.Dequeue(); byte[] bytes_cmdid = new byte[2]; byte[] bytes_seq = new byte[4]; byte[] bytes_body = new byte[bts.Length - 6]; ByteAr_b.PickBytes(bts, bytes_cmdid.Length, bytes_cmdid, 0); ByteAr_b.PickBytes(bts, bytes_seq.Length, bytes_seq, 2); ByteAr_b.PickBytes(bts, bytes_body.Length, bytes_body, bytes_cmdid.Length + bytes_seq.Length); ushort head = ByteAr_b.b2us(bytes_cmdid); if (msgStructDic.ContainsKey(head)) { pt = msgStructDic[head].createNew(); pt.seq = ByteAr_b.b2ui(bytes_seq); pt.fromBinary(bytes_body); } } } if (pt != null) { if (screen_Debug_Log_S2C) { GameSys.LogInternal("[S] to [C] :" + Convert.ToString(pt.GetID(), 16), false); } if (editor_Debug_Log_S2C) { Debug.Log("[S] to [C] :" + Convert.ToString(pt.GetID(), 16)); } MsgHander.ProcComand(pt); } } } }
public ushort Read_ushort() { byte[] bytes = Read_bytes(2); return(ByteAr_b.b2us(bytes)); }