示例#1
0
        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();
        }
示例#2
0
        UdpSocket(UdpPlatform platform, UdpSerializerFactory serializerFactory, UdpConfig config)
        {
            this.platform          = platform;
            this.serializerFactory = serializerFactory;
            this.Config            = config.Duplicate();

            random        = new Random(500);
            state         = udpSocketState.Created;
            receiveBuffer = new byte[config.MtuMax * 2];
            objectBuffer  = 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();
        }
示例#3
0
 public static UdpSocket Create(UdpPlatform platform, UdpSerializerFactory serializer)
 {
     return(Create(platform, serializer, new UdpConfig()));
 }
示例#4
0
        /*
         #region Partial Methods
         * void DelayPacket (UdpEndPoint ep, byte[] data, int length);
         * void RecvDelayedPackets ();
         #endregion*/

        public static UdpSocket Create(UdpPlatform platform, UdpSerializerFactory serializer, UdpConfig config)
        {
            return(new UdpSocket(platform, serializer, config));
        }