private void ListenForNewUnits(UnitProvider unitProvider) { // create socket listener IPAddress ip = Dns.GetHostEntry("localhost").AddressList[0]; TcpListener tcpListener = new TcpListener(ip, 8080); TcpClient tcpClient = default(TcpClient); // start socket listener try { tcpListener.Start(); } catch (Exception exception) { Console.WriteLine(exception.ToString()); } // read message from socket while (true) { tcpClient = tcpListener.AcceptTcpClient(); byte[] receivedBuffer = new byte[200]; NetworkStream networkStream = tcpClient.GetStream(); networkStream.Read(receivedBuffer, 0, receivedBuffer.Length); Unit unit = UnitDecoder.DecodeUnit(receivedBuffer); unitProvider.ProvideUnit(unit); } }