Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Opening connection...");
            using (ITwitterMessageService connection = new TcpMessageService(10101, "localhost", new ConsoleLogger()))
            {
                connection.OnMessageRecieved.Subscribe(ReceiveMessage);
                connection.Start();
                Console.WriteLine("Connection opened.");
                Console.WriteLine("Type 'exit' to close connection.");

                string line = null;
                while ((line = Console.ReadLine()) != null)
                {
                    if (line.ToLowerInvariant().Equals("exit"))
                    {
                        break;
                    }
                    else
                    {
                        connection.Send(line);
                    }
                }
            }
            Console.WriteLine("Closing connection...");
        }
Exemplo n.º 2
0
 public void Start()
 {
     _tcpListener = new TcpListener(IPAddress.Parse(_tcpEndpointDetails.IpAddress), _tcpEndpointDetails.Port);
     _tcpListener.Start();
     try
     {
         TcpClient tcpClient = null;
         while ((tcpClient = _tcpListener.AcceptTcpClient()) != null)
         {
             ITwitterMessageService twitterClient = new TcpMessageService(tcpClient, _logger);
             _twitterHandler.Add(twitterClient);
             twitterClient.Start();
             _logger.LogMessage("Listener added new Tcp Client : " + twitterClient.SessionId);
         }
         _listenerStatus = ListenerStatus.Started;
     }
     catch (SocketException ex)
     {
         _logger.LogException("Start - Listener: ", ex);
     }
 }