Exemplo n.º 1
0
        protected void ListenForMessage()
        {
            byte[] message = new byte[4096];
            int    bytesRead;

            while (stream.CanRead)
            {
                bytesRead = 0;
                try
                {
                    bytesRead = stream.Read(message, 0, 4096);
                }
                catch
                {
                    break;
                }

                if (bytesRead == 0)
                {
                    break;
                }
                string signal = encoder.GetString(message, 0, bytesRead);
                Console.WriteLine(message);
                MessageArgs myArgs = new MessageArgs(signal);
                OnNewMessageRecived(this, myArgs);
            }
            if (client != null)
            {
                try
                {
                    var args = new MessageArgs("Disconnected from cloud");
                    OnNewSignalization(this, args);

                    client.GetStream().Close();
                    client.Close();
                    client = null;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                    Console.WriteLine("Exception in disconnecting from cloud");
                }
            }
        }
Exemplo n.º 2
0
        private void notifyListeners(string signal, TcpClient clientSocket)
        {
            MessageArgs myArgs = new MessageArgs(signal, clientSocket);

            OnNewMessageRecived?.Invoke(this, myArgs);
        }