private void RecHandler(byte[] buf, ASynServerKcp serverKcp) { int playerId = BitConverter.ToInt32(buf, 0); serverKcp.PlayerId = playerId; MsgID msgId = (MsgID)BitConverter.ToInt32(buf, 4); MemoryStream stream = new MemoryStream(buf, 8, buf.Length - 8); IMessage msg = null; switch (msgId) { case MsgID.LoginReq: msg = LoginReq.Parser.ParseFrom(stream); break; case MsgID.LoginOutReq: msg = LoginOutReq.Parser.ParseFrom(stream); break; case MsgID.SteerPositionReq: //msg = SteerPositionReq.Descriptor.Parser.ParseFrom(stream); msg = SteerPositionReq.Parser.ParseFrom(stream); break; default: Log4U.LogDebug("SimulateServerUDP:RecHandler Not handler msgId=", msgId); break; } stream.Dispose(); Log4U.LogDebug("SimulateServerUDP:RecHandler<<<<<< playerId=", playerId, " msgId=", msgId, " msg=", msg); MessageDispatcher.GetInstance().DispatchMessageAsyn(msgId, msg, playerId); }
private void ReceiveAsyn(IAsyncResult arg) { byte[] rcvBuf = _socket.EndReceive(arg, ref _remoteEP); string epKey = _remoteEP.Address + ":" + _remoteEP.Port; //Log4U.LogDebug("ASynKcpUdpServerSocket:ReceiveAsyn Message receive from ", epKey); ASynServerKcp aSynKcp; if (_aSynKcpDic.ContainsKey(epKey)) { aSynKcp = _aSynKcpDic[epKey]; } else { aSynKcp = new ASynServerKcp((uint)(_aSynKcpDic.Count + 1), _socket, _remoteEP, _recHandler); _aSynKcpDic.Add(epKey, aSynKcp); } aSynKcp.Input(rcvBuf); _socket.BeginReceive(ReceiveAsyn, this); }