Exemplo n.º 1
0
        private void OnAccept(IAsyncResult result)
        {
            TcpClient tcpClient = tcpServer.EndAcceptTcpClient(result);

            byte[] buffer  = new byte[1024]; //tcpClient.ReceiveBufferSize
            Client client  = new Client(tcpClient, buffer);
            string message = "Connected to " + GetIPv4(Dns.GetHostEntry(Dns.GetHostName()).AddressList).ToString();

            try
            {
                lock (this.Clients)
                {
                    this.Clients.Add(client);
                    //this.SendMessage(tcpClient, message);
                }
            }
            catch { }

            tcpServer.BeginAcceptTcpClient(new AsyncCallback(OnAccept), tcpServer);
            client.NetworkStream.BeginRead(client.Buffer, 0, client.Buffer.Length, new AsyncCallback(OnRead), client);
        }
Exemplo n.º 2
0
 public void Start()
 {
     tcpServer = new TcpServer(IPAddress.Any, Port);
     tcpServer.Start();
     tcpServer.BeginAcceptTcpClient(new System.AsyncCallback(OnAccept), tcpServer);
 }