UdpSocket(UdpPlatform platform, UdpSerializerFactory serializerFactory, UdpConfig config)
        {
            this.platform          = platform;
            this.serializerFactory = serializerFactory;
            this.Config            = config.Duplicate();
            this.configCopy        = config;

            state          = UdpSocketState.Created;
            random         = new System.Random();
            stats          = new UdpStats();
            availableEvent = new AutoResetEvent(false);

            if (this.Config.NoiseFunction == null)
            {
                this.Config.NoiseFunction = delegate() { return((float)random.NextDouble()); };
            }

            readStream  = new UdpStream(new byte[config.PacketSize * 2]);
            writeStream = new UdpStream(new byte[config.PacketSize * 2]);
            streamPool  = new UdpStreamPool(this);

            eventQueueIn  = new Queue <UdpEvent>(config.InitialEventQueueSize);
            eventQueueOut = new Queue <UdpEvent>(config.InitialEventQueueSize);

            threadSocket              = new Thread(NetworkLoop);
            threadSocket.Name         = "udpkit thread";
            threadSocket.IsBackground = true;
            threadSocket.Start();
        }
Exemple #2
0
        internal UdpConnection(UdpSocket s, UdpConnectionMode m, UdpEndPoint ep)
        {
            socket        = s;
            mode          = m;
            endpoint      = ep;
            stats         = new UdpStats();
            networkRtt    = socket.Config.DefaultNetworkPing;
            aliasedRtt    = socket.Config.DefaultAliasedPing;
            mtu           = socket.Config.DefaultMtu;
            alwaysSendMtu = socket.Config.DefaultAlwaysSendMtu;
            state         = UdpConnectionState.Connecting;
            recvTime      = socket.GetCurrentTime();
            sendTime      = recvTime;
            sendWindow    = new UdpRingBuffer <UdpHandle>(socket.Config.PacketWindow);

            serializer            = socket.CreateSerializer();
            serializer.Connection = this;
            serializer.Created();
        }
Exemple #3
0
        UdpSocket(UdpPlatform platform, UdpSerializerFactory serializerFactory, UdpConfig config)
        {
            this.platform          = platform;
            this.serializerFactory = serializerFactory;
            this.Config            = config.Duplicate();

            state  = udpSocketState.Created;
            random = new Random();
            stats  = new UdpStats();

            readStream  = new UdpStream(new byte[config.MtuMax * 2]);
            writeStream = new UdpStream(new byte[config.MtuMax * 2]);

            eventQueueIn  = new Queue <UdpEvent>(config.InitialEventQueueSize);
            eventQueueOut = new Queue <UdpEvent>(config.InitialEventQueueSize);

            threadSocket              = new Thread(NetworkLoop);
            threadSocket.Name         = "udpkit thread";
            threadSocket.IsBackground = true;
            threadSocket.Start();
        }