Пример #1
0
        /// <summary>
        /// Create a new SocketSet, and add it to the list.
        /// </summary>
        /// <param name="socket"></param>
        /// <returns></returns>
        private SocketSet CreateSocketSet(Socket socket)
        {
            var sset = new SocketSet(socket);

            this._socketSets.Add((IPEndPoint)socket.RemoteEndPoint, sset);
            return(sset);
        }
Пример #2
0
        /// <summary>
        /// Initialize the socket, start Server.
        /// </summary>
        private void Init()
        {
            this.LocalEndPoint  = new IPEndPoint(this.LocalIpAddress, this.LocalPort);
            this.RemoteEndPoint = new IPEndPoint(this.RemoteIpAddress, this.RemotePort);

            this._socket = new Socket(SocketType.Dgram, ProtocolType.Udp);
            this._socket.Bind(this.LocalEndPoint);

            var sset     = new SocketSet(this._socket);
            var endPoint = new IPEndPoint(IPAddress.Any, 0) as EndPoint;

            // THANKS bidasknakayama!
            // Remote info could be acquired on UDP.
            this._socket.BeginReceiveMessageFrom(
                sset.ReceiveBuffer,
                0,
                sset.ReceiveBuffer.Length,
                SocketFlags.None,
                ref endPoint,
                this.OnRecievedPrivate,
                sset);

            Xb.Util.Out($"Listen Started.");
        }