public static int Dispatch(ByteReader reader, ReceiveMsgCallback callback) { if (callback == null) { return(0); } /* * 协议格式: * short: 协议大小 * short: 协议号 * 动态长度 */ int LastPos = 0; try { do { int msg_len = reader.ReadShort(); int msg_start = reader.GetPos(); int id = reader.ReadShort(); INetMessage msg = NetCenter.Recognize(id, reader); if (msg == null) { break; } // 协议大小不对! if (msg_len != (reader.GetPos() - msg_start)) { break; } LastPos = reader.GetPos(); try { callback(id, msg); } catch (Exception) { } }while (!reader.IsEnd()); } catch (Exception) { } return(LastPos); }
public void SetReceiveCallback(ReceiveMsgCallback cb) { mCallback = cb; }