public override void Init() { instance = this; if (msgIDs == null) { msgIDs = new CMessageID(); } sendStack = new Stack <SendCallback>(); msgBuilders = new List <FlatBufferBuilder>(builderLimit) { }; for (int i = 0; i < builderLimit; i++) { msgBuilders.Add(new FlatBufferBuilder(32)); } csocket = new CSocket(); csocket.Init(); // //udp相关 updSocket = new CSocketUDP(); updSocket.Init(); updSocket.BeginReceive(); CConstVar.LocalPort = updSocket.GetLocalPort(); //loopback loopbacks = new Loopback[2]; //队列 sendPacketQueue = new CircularBuffer <PacketQueue>(10); needUpdate = true; // HuffmanMsg.Init(); }
public void handle(ByteBuffer buffer) { CMessageID code = (CMessageID)buffer.readShort(); buffer.code = code; // switch (code) { // case Code.S_OtherMove:App.sceneManager.handle(buffer); break; // } }
public void DispatchMessage(FlatBuffers.ByteBuffer buffer) { var type = CMessageID.GetMsgType(GetMsgID(buffer)); List <Callback> calls; if (msgRegister.TryGetValue(type, out calls)) { int len = calls.Count; for (int i = 0; i < len; i++) { calls[i].method.Invoke(calls[i].instance, new object[] { buffer }); } } }
public static ByteBuffer createUdp(CMessageID code, int sessionId) { ByteBuffer buffer; lock (writePool) { buffer = writePool.get(); } if (buffer.data == null) { buffer.data = new byte[MAX]; } buffer.readIndex = 0; buffer.writeIndex = 0; buffer.writeShort((int)code); buffer.writeInt(sessionId); return(buffer); }
/// <summary> /// create a write buffer. /// </summary> /// <param name="code"></param> /// <returns></returns> public static ByteBuffer create(CMessageID code) { ByteBuffer buffer; lock (writePool) { buffer = writePool.get(); } if (buffer.data == null) { buffer.data = new byte[MAX]; } buffer.readIndex = 0; buffer.writeIndex = 0; buffer.writeInt(1000); buffer.writeShort((short)code); return(buffer); }
public void handle(ByteBuffer buffer) { CMessageID code = (CMessageID)buffer.readShort(); buffer.code = code; UtilLog.Log("收到消息" + code); switch (code) { case CMessageID.MS_Error: break; default: handles[code](buffer); // BaseHandle baseHandle = handles[code]; // if (baseHandle != null) // { // baseHandle.onResult(code, buffer); // } break; } }
public static void RegistMsg(CMessageID CMsId, DelegateMethod func) { handles.Add(CMsId, func); }