private void DoReceiveInMain() { recvBufQueue.Switch(); while (!recvBufQueue.Empty()) { var recvBufferRaw = recvBufQueue.Pop(); int ret = kcp.Input(recvBufferRaw, recvBufferRaw.Length); if (ret < 0) { Debuger.LogError("收到不正确的KCP包!Ret:{0}", ret); return; } needKcpUpdateFlag = true; for (int size = kcp.PeekSize(); size > 0; size = kcp.PeekSize()) { var recvBuffer = new byte[size]; if (kcp.Recv(recvBuffer) > 0) { if (listener != null) { FSPDataCToS data = ProtoBuffUtility.Deserialize <FSPDataCToS>(recvBuffer); listener(data); } else { Debuger.LogError("找不到接收者!"); } } } } }
private void OnRecvFromSession(FSPDataCToS data) { if (session.IsEndPointChanged) { session.IsEndPointChanged = false; hasAuthed = false; } recvListener?.Invoke(this, data.msg); }
public void Clean() { kcp?.Dispose(); kcp = null; recvListener = null; sendBufferTemp = null; recvBufferTemp = null; tempSendData = null; recvBuffQueue.Clear(); recvBuffQueue = null; Close(); }
public void Init(uint sessionid) { sessionID = sessionid; sendBufferTemp = new byte[4096]; recvBufferTemp = new byte[4096]; tempSendData = new FSPDataCToS(); recvBuffQueue = new SwitchQueue <byte[]>(); tempSendData.sessionID = sessionid; tempSendData.msg = new FSPMessage(); kcp = new KCP(sessionid, HandleKcpSend); kcp.NoDelay(1, 10, 2, 1); kcp.WndSize(128, 128); }