示例#1
0
        /// <summary>
        /// Begin listening for UDP connections. Should not be called directly - instead use <see cref="M:Cell.Core.ServerBase.Start(System.Boolean,System.Boolean)" />
        /// <seealso cref="P:Cell.Core.ServerBase.TCPEnabled" />
        /// </summary>
        public void StartUDP()
        {
            if (this.UdpEnabledEnabled || !this._running)
            {
                return;
            }
            IPEndPoint endPoint = new IPEndPoint(this.UdpIP, this.UdpPort);

            ServerBase.VerifyEndpointAddress(endPoint);
            this._udpListen = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            this._udpListen.Bind((EndPoint)endPoint);
            this.StartReceivingUdp((SocketAsyncEventArgs)null);
            this.UdpEnabledEnabled = true;
            this.Info((IClient)null, Cell_Core.ListeningUDPSocket, (object)this.UdpEndPoint);
        }
示例#2
0
        /// <summary>
        /// Begin listening for TCP connections. Should not be called directly - instead use <see cref="M:Cell.Core.ServerBase.Start(System.Boolean,System.Boolean)" />
        /// <seealso cref="P:Cell.Core.ServerBase.TCPEnabled" />
        /// </summary>
        protected void StartTCP()
        {
            if (this.TcpEnabledEnabled || !this._running)
            {
                return;
            }
            ServerBase.VerifyEndpointAddress(this.TcpEndPoint);
            this._tcpListen = new Socket(this.TcpEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                this._tcpListen.Bind((EndPoint)this.TcpEndPoint);
            }
            catch (Exception ex)
            {
                ServerBase.log.Error("Could not bind to Address {0}: {1}", (object)this.TcpEndPoint, (object)ex);
                return;
            }

            this._tcpListen.Listen(this.MaximumPendingConnections);
            SocketHelpers.SetListenSocketOptions(this._tcpListen);
            this.StartAccept((SocketAsyncEventArgs)null);
            this.TcpEnabledEnabled = true;
            this.Info((IClient)null, Cell_Core.ListeningTCPSocket, (object)this.TcpEndPoint);
        }