internal NetworkConnection(INetworkInterface networkInterface, int connectionId) { NetworkInterface = networkInterface; MessageHandlers = networkInterface.MessageHandlers; Status = ConnectionStatus.Connecting; Id = connectionId; connectTask = new TaskCompletionSource <object>(); }
protected NetworkInterface(int maxMsgSize) { MessageHandlers = new MessageHandlers(); connectionMap = new Dictionary <int, NetworkConnection>(); connections = new List <NetworkConnection>(); Connections = new ReadOnlyCollection <NetworkConnection>(connections); ReadBuffer = ArrayPool <byte> .Shared.Rent(maxMsgSize); messageDeserializer = new Deserializer(ReadBuffer); }
protected virtual void OnRecieveData(int connectionId, byte[] data, int dataSize) { NetworkConnection connection; if (!connectionMap.TryGetValue(connectionId, out connection)) { return; } var decompressed = ArrayPool <byte> .Shared.Rent(dataSize); CLZF2.Decompress(data, ref decompressed, dataSize); messageDeserializer.Replace(decompressed); messageDeserializer.SeekZero(); MessageHandlers.Execute(connection, messageDeserializer); }