public NetworkContext(NetworkContextOptions contextOptions, IServiceProvider serviceProvider) { var loggerFactory = serviceProvider.GetService <ILoggerFactory>(); _connection = contextOptions.Stream; _readBuffer = ArrayPool <byte> .Shared.Rent(4096); _cancellationTokenSource = new CancellationTokenSource(); _processRead = new SemaphoreSlim(1); _processSend = new SemaphoreSlim(1); _sendStopwatch = new Stopwatch(); Options = contextOptions; Logger = loggerFactory.CreateLogger <NetworkContext <TNetworkContext> >(); MessageSerialService = serviceProvider.GetService <IMessageSerialService>(); UnitOfWorkFactory = serviceProvider.GetService <IUnitOfWorkFactory>(); CryptographyService = new PlainCryptographyService(); _networkMessageFactory = serviceProvider.GetService <INetworkMessageFactory>(); _networkMessageHandlerService = serviceProvider.GetService <INetworkMessageHandlerService <TNetworkContext> >(); _messageChecksumService = serviceProvider.GetService <IMessageChecksumService>(); _cryptographyServiceFactory = serviceProvider.GetService <ICryptographyServiceFactory>(); _self = (TNetworkContext)(object)this; _alignBuffer = false; _connected = true; _saidHello = false; }
/// <summary> /// Creates a new <see cref="NetClient"/>-based network message router service for Lidgren. /// </summary> /// <param name="messageFactory">The network message factory.</param> /// <param name="peerObj">The <see cref="NetPeer"/> object.</param> /// <param name="serializerStrategy">Serialization strategy.</param> public LidgrenClientNetworkMessageRouterService(INetworkMessageFactory messageFactory, NetConnection connection, ISerializerStrategy serializerStrategy) : base(messageFactory, connection) { if (serializerStrategy == null) throw new ArgumentNullException(nameof(serializerStrategy), $"Cannot provide a null {nameof(ISerializerStrategy)} to {nameof(LidgrenClientNetworkMessageRouterService)}."); serializer = serializerStrategy; }
/// <summary> /// Creates a new <see cref="NetClient"/>-based network message router service for Lidgren. /// </summary> /// <param name="messageFactory">The network message factory.</param> /// <param name="peerObj">The <see cref="NetPeer"/> object.</param> /// <param name="serializerStrategy">Serialization strategy.</param> public LidgrenServerNetworkMessageRouterService(INetworkMessageFactory messageFactory, NetConnection connection, ISerializerStrategy serializerStrategy) : base(messageFactory, connection) { if (serializerStrategy == null) { throw new ArgumentNullException(nameof(serializerStrategy)); } serializer = serializerStrategy; }
} //protected so child can handle sending protected LidgrenNetworkMessageRouterService(INetworkMessageFactory messageFactory, NetConnection connection) { if (messageFactory == null) { throw new ArgumentNullException(nameof(messageFactory), $"Cannot provide a null {nameof(INetworkMessageFactory)} service."); } if (connection == null) { throw new ArgumentNullException(nameof(connection), $"Cannot provide a null {nameof(NetConnection)} service."); } lidgrenNetworkConnection = connection; networkMessageFactory = messageFactory; }
public NetworkClientWithMessageFactory(INetworkMessageFactory networkMessageFactory) { _networkMessageFactory = networkMessageFactory; }