Esempio n. 1
0
        /// <summary>
        /// Listens for and handles all incoming transmissions.
        /// </summary>
        private void Listener()
        {
            while (true)
            {
                Console.WriteLine("Waiting for connection");
                TcpClient lClient = _internalServer.AcceptTcpClient();
                Console.WriteLine("Incoming connection from {0}", ((IPEndPoint)lClient.Client.RemoteEndPoint).Address.ToString());
                //connectedClients.Add(((IPEndPoint)lClient.Client.RemoteEndPoint).Address.ToString());
                NetworkStream stream = lClient.GetStream();
                byte[]        bytes  = new byte[256];
                string        data   = null;
                int           i;

                while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                {
                    data = Encoding.ASCII.GetString(bytes, 0, i);

                    ReceivedDataEventArgs e = new ReceivedDataEventArgs();
                    e.Data = data;

                    ReceivedData?.Invoke(this, e); // that's a neat shortcut tbh
                }
                stream.Close();
                lClient.Close();
                Console.WriteLine("Connection closed");
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Handle the incoming data.
 /// </summary>
 /// <param name="s">The sender object.</param>
 /// <param name="e">Event arguments</param>
 private void HandleIncomingData(object s, ReceivedDataEventArgs e)
 {
 }