public void OnReceiveKcp(byte[] data, IPEndPoint ip) { if (mKCP == null) { return; } lock (mKCP) { mKCP.Input(data); for (int size = mKCP.PeekSize(); size > 0; size = mKCP.PeekSize()) { MessageBuffer message = new MessageBuffer(size); if (mKCP.Recv(message.buffer) > 0) { if (message.IsValid() && message.extra() == id) { if (udpAdress == null || udpAdress.Equals(ip) == false) { udpAdress = ip; } mService.OnReceive(new MessageInfo(message, this)); } } } } }
public void ProcessRecv(UInt32 current) { var queue = SwitchRecvQueue(); while (queue.Count > 0) { lastRecvTime = current; var data = queue.Dequeue(); int r = kcp.Input(data, 0, data.Length); Debug.Assert(r >= 0); needUpdate = true; while (true) { var size = kcp.PeekSize(); if (size > 0) { r = kcp.Recv(kcpRcvBuf, 0, kcpRcvBuf.Length); if (r <= 0) { break; } handler(kcpRcvBuf, size); } else { break; } } } }
private void ReceiveThread() { while (IsConnected) { try { IPEndPoint ip = mServerAdress; byte[] data = Receive(ref ip); if (data.Length > 0) { lock (mKCP) { mKCP.Input(data); for (int size = mKCP.PeekSize(); size > 0; size = mKCP.PeekSize()) { MessageBuffer message = new MessageBuffer(size); if (mKCP.Recv(message.DataBuffer) > 0) { if (message.IsValid()) { OnMessage?.Invoke(message); } } } } } } catch (Exception e) { Close(); throw e; } Thread.Sleep(1); } }
private void OnReceiveKcp(byte[] data) { if (mKCP == null) { return; } lock (mKCP) { mKCP.Input(data); for (int size = mKCP.PeekSize(); size > 0; size = mKCP.PeekSize()) { MessageBuffer message = new MessageBuffer(size); if (mKCP.Recv(message.buffer) > 0) { if (onMessage != null && message.IsValid()) { onMessage(message); } } } } }