コード例 #1
0
        public async void Start()
        {
            listener = new TcpListener(IPAddress.Parse(LocalAddress), Port);
            listener.Start();
            Running = true;
            logger.Info($"Server listening at {LocalAddress}:{Port}");

            await Task.Run(() =>
            {
                while (Running)
                {
                    if (!listener.Pending())
                    {
                        Thread.Sleep(250);
                        continue;
                    }

                    TcpClient client = listener.AcceptTcpClient();
                    AsyncTcpClient <TOpcode> asyncTcpClient = new AsyncTcpClient <TOpcode>(client);
                    clients[asyncTcpClient.Id] = asyncTcpClient;
                    OnClientConnected?.Invoke(this, new TcpSocketEventArgs <TOpcode>(asyncTcpClient));
                }
            });
        }
コード例 #2
0
 public TcpSocketEventArgs(AsyncTcpClient <TOpcode> tcpClient)
 {
     TcpClient = tcpClient;
 }