Auxilium_Server.Classes.Server.Listen C# (CSharp) Method

Listen() public method

public Listen ( ushort port ) : void
port ushort
return void
        public void Listen(ushort port)
        {
            try
            {
                if (!Listening)
                {
                    _clients = new List<Client>();

                    _item = new SocketAsyncEventArgs();
                    _item.Completed += Process;

                    _handle = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                    //_handle.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);

                    _handle.Bind(new IPEndPoint(IPAddress.Any, port));
                    _handle.Listen(10);

                    Processing = false;
                    Listening = true;

                    OnServerState(true);
                    if (!_handle.AcceptAsync(_item))
                        Process(null, _item);
                }
            }
            catch
            {
                Disconnect();
            }
        }

Usage Example

Example #1
0
        static void Main(string[] args)
        {
            SQL = new MySqlConnection();
            SQL.ConnectionString = "server=localhost;uid=auxilium;pwd=123456;database=auxilium";
            SQL.Open();

            Channels = new string[] { "Lounge", "VB.NET", "C#" };

            Packer = new Pack();
            Listener = new Server();

            Listener.Size = 2048;
            Listener.Client_Read += Client_Read;
            Listener.MaxConnections = 10000;
            Listener.Client_State += Client_State;
            Listener.Server_State += Server_State;
            Listener.Listen(Port);

            while (true)
            {
                string str = string.Empty;
                if (Console.ReadKey().Key == ConsoleKey.Escape)
                    break;
                else if (!string.IsNullOrWhiteSpace(str = Console.ReadLine()))
                    ProcessCommand(str);
            }
        }
All Usage Examples Of Auxilium_Server.Classes.Server::Listen