Esempio n. 1
0
        /// <summary>
        /// Create a new incoming udp connection to handle communication to a single endpoint.
        /// </summary>
        public UdpConnection(UdpServer server, IPEndPoint remoteEndpoint, IPEndPoint localEndpoint, byte[] buffer, int count)
        {
            // persist the server
            Server         = server;
            RemoteEndPoint = remoteEndpoint;

            _timeoutTimer = new Timer(_timeoutMilliseconds, ActionSet.New(ProcessError, new TimeoutException("UdpConnection timeout.")));

            _header             = new UdpHeader();
            _header.Compression = _defaultCompression = DecompressionMethods.None;

            // create the encoder
            _encoder = Encoding.UTF8.GetEncoder();
            _lock    = new Lock();
            _message = new UdpMessage(this);

            _messages  = new ArrayRig <UdpMessage>();
            _onMessage = new ActionPop <UdpMessage>();

            _errors  = new ArrayRig <Exception>();
            _onError = new ActionPop <Exception>();

            // call on received for the first buffer
            OnReceived(RemoteEndPoint, buffer, count);

            // create a socket instance for the udp connection
            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            // create an async socket to manage the socket
            AsyncSocket = new AsyncUdpSocket(socket, localEndpoint, OnReceived, ProcessError);
            AsyncSocket.TargetEndPoint = RemoteEndPoint;
        }
Esempio n. 2
0
        /// <summary>
        /// Create a new udp connection to handle communication to a single endpoint from the specified socket.
        /// </summary>
        public UdpConnection(UdpServer server, Socket socket, IPEndPoint remoteEndpoint)
        {
            // persist the server
            Server         = server;
            RemoteEndPoint = remoteEndpoint;

            _timeoutTimer = new Timer(_timeoutMilliseconds, ActionSet.New(ProcessError, new TimeoutException("UdpConnection timeout.")));

            _header             = new UdpHeader();
            _header.Compression = _defaultCompression = DecompressionMethods.None;

            // create the encoder
            _encoder = Encoding.UTF8.GetEncoder();
            _lock    = new Lock();
            _message = new UdpMessage(this);

            _messages  = new ArrayRig <UdpMessage>();
            _onMessage = new ActionPop <UdpMessage>();

            _errors  = new ArrayRig <Exception>();
            _onError = new ActionPop <Exception>();

            // create an async socket to manage the socket
            AsyncSocket = new AsyncUdpSocket(socket, (IPEndPoint)socket.LocalEndPoint, OnReceived, ProcessError);
            AsyncSocket.TargetEndPoint = RemoteEndPoint;
        }
Esempio n. 3
0
        //----------------------------------//

        internal UdpMessage(UdpConnection connection)
        {
            // reference the web client
            Connection = connection;

            _streamBuffer = new ByteBuffer(new MemoryStream(200));

            Header = new UdpHeader();

            _remainingBodyLength = -1;
        }