internal void ProcessData(ProcessDataOutputHandler outputHandler) { if (this._cache.length == 0) { return; } this._activeDateTime = TimeUtils.utcTime; byte[] data; lock (this._cache) { int len = LengthEncoder.Decode(this._cache.GetBuffer(), 0, this._cache.position, out data); if (data == null) { return; } this._cache.Strip(len, ( int )this._cache.length - len); } Packet packet = NetworkHelper.DecodePacket(data, 0, data.Length); packet.OnReceive(); outputHandler.Invoke(packet); if (this._cache.length > 0) { this.ProcessData(outputHandler); } }
public void Send(byte[] data, int offset, int size) { if (this._socket == null) { return; } data = LengthEncoder.Encode(data, offset, size); try { this._socket.Send(data, 0, data.Length, SocketFlags.None); } catch (SocketException e) { this.MarkToClose(e.ToString(), e.SocketErrorCode); } }
public void Send(byte[] data, int offset, int size) { if (this._conn == null) { return; } data = LengthEncoder.Encode(data, offset, size); try { this._conn.Send(data, 0, data.Length, SocketFlags.None); } catch (ObjectDisposedException) { } catch (SocketException e) { this.MarkToDisconnect($"Client send error, remote Address: {this.remoteEndPoint}", e.SocketErrorCode); } }
private void ProcessReceiveDatas() { if (this._cache.length == 0) { return; } byte[] data; lock (this._cache) { int len = LengthEncoder.Decode(this._cache.GetBuffer(), 0, this._cache.position, out data); if (data == null) { return; } this._cache.Strip(len, ( int )this._cache.length - len); } Packet packet = NetworkHelper.DecodePacket(data, 0, data.Length); packet.OnReceive(); if (packet.module == NetworkConfig.INTERNAL_MODULE && packet.command == 1) { this.id = (( PacketAccept )packet).tokenId; this._state = State.Connected; this._pingScheduler.Start(NetworkConfig.PING_INTERVAL, this.SendPing); this.OnSocketEvent?.Invoke(new SocketEvent(SocketEvent.Type.Connect, string.Empty, SocketError.Success, null)); } else { this.OnSocketEvent?.Invoke(new SocketEvent(SocketEvent.Type.Receive, packet, null)); } if (this._cache.length > 0) { this.ProcessReceiveDatas(); } }