Beispiel #1
0
        public Server(ServerBuilderOptions options,
                      ITcpConnections tcpConnections,
                      ITcpSocketListenerFactory tcpSocketListenerFactory,
                      IUdpSocketListener udpSocketListener,
                      IBufferManager bufferManager,
                      IServerInformation serverInformation,
                      IPacketSerialiser packetSerialiser)
        {
            this.options          = options;
            this.tcpConnections   = tcpConnections;
            Information           = serverInformation;
            this.packetSerialiser = packetSerialiser;
            bufferManager.InitBuffer();

            if (options.TcpPort > 0)
            {
                TcpListener = tcpSocketListenerFactory.Create();
            }

            if (options.UdpPort > 0)
            {
                UdpListener = udpSocketListener;
            }

            Task.Factory.StartNew(() =>
            {
                while (Information.IsRunning)
                {
                    if (eventArgs == null)
                    {
                        eventArgs = new ServerInformationEventArgs();
                    }

                    eventArgs.ProcessedTcpPackets =
                        serverInformation.ProcessedTcpPackets;
                    eventArgs.InvalidTcpPackets =
                        serverInformation.InvalidTcpPackets;
                    eventArgs.ProcessedUdpPackets =
                        serverInformation.ProcessedUdpPackets;
                    eventArgs.InvalidUdpPackets =
                        serverInformation.InvalidUdpPackets;
                    eventArgs.TcpConnections = tcpConnections.GetConnections()
                                               .Count;

                    ServerInformationUpdated?.Invoke(this, eventArgs);

                    Information.ProcessedTcpPackets = 0;
                    Information.InvalidTcpPackets   = 0;
                    Information.ProcessedUdpPackets = 0;
                    Information.InvalidUdpPackets   = 0;

                    Thread.Sleep(10000);
                }
            });
        }
        public IUdpSocketListener Create()
        {
            /*return new UdpSocketListener(this.options,
             *  this.logger,
             *  this.serverPacketProcessor,
             *  this.bufferManager);*/

            return(_clientListener ?? (_clientListener = new UdpClientListener(options,
                                                                               logger,
                                                                               serverPacketProcessor,
                                                                               serverInformation)));
        }
Beispiel #3
0
 public UdpSocketSender(IUdpSocketListener udpSocketListener, IPacketSerialiser packetSerialiser)
 {
     _udpSocketListener = udpSocketListener;
     _packetSerialiser  = packetSerialiser;
 }