예제 #1
0
        UdpSocket(UdpPlatform platform, UdpSerializerFactory serializerFactory, UdpConfig config)
        {
            this.platform          = platform;
            this.serializerFactory = serializerFactory;
            this.Config            = config.Duplicate();
            this.configCopy        = config;

            serializer     = CreateSerializer();
            state          = UdpSocketState.Created;
            random         = new 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
 internal UdpConnection(UdpSocket sock, UdpConnectionMode m, UdpEndPoint ep)
 {
     socket        = sock;
     mode          = m;
     endpoint      = ep;
     networkRtt    = socket.Config.DefaultNetworkPing;
     aliasedRtt    = socket.Config.DefaultAliasedPing;
     mtu           = sock.Config.DefaultMtu;
     alwaysSendMtu = sock.Config.DefaultAlwaysSendMtu;
     serializer    = sock.CreateSerializer();
     state         = UdpConnectionState.Connecting;
     recvTime      = socket.GetCurrentTime();
     sendTime      = recvTime;
     stats         = new UdpConnectionStats();
     sendWindow    = new UdpRingBuffer <UdpHandle>(sock.Config.PacketWindow);
 }
예제 #3
0
 internal UdpConnection(UdpSocket sock, UdpConnectionMode m, UdpEndPoint ep)
 {
     socket = sock;
     mode = m;
     endpoint = ep;
     networkRtt = socket.Config.DefaultNetworkPing;
     aliasedRtt = socket.Config.DefaultAliasedPing;
     mtu = sock.Config.DefaultMtu;
     alwaysSendMtu = sock.Config.DefaultAlwaysSendMtu;
     serializer = sock.CreateSerializer();
     state = UdpConnectionState.Connecting;
     recvTime = socket.GetCurrentTime();
     sendTime = recvTime;
     stats = new UdpConnectionStats();
     sendWindow = new UdpRingBuffer<UdpHandle>(sock.Config.PacketWindow);
 }