public byte[] ProcessMessage(byte[] request) { System.Net.Sockets.TcpClient socketForServer; Console.WriteLine("Client sending message"); try { socketForServer = new System.Net.Sockets.TcpClient("localHost", _port ); } catch { Console.WriteLine( "Failed to connect to server at {0}:999", "localhost"); return null; } NetworkStream networkStream = socketForServer.GetStream(); argot.TypeInputStream inStream = new argot.TypeInputStream(networkStream, _map ); argot.TypeOutputStream outStream = new argot.TypeOutputStream(networkStream, _map ); byte[] response = new byte[0]; try { Console.WriteLine("client: request: " + request.Length ); outStream.WriteObject( "u16binary", request ); networkStream.Flush(); //*** WITHOUT THIS IT FAilS WITH System.IO.EndOfStreamException //*** Error Message: Attempted to read past the end of the stream. System.Threading.Thread.Sleep(500); Console.WriteLine("client: reading resposne" ); response = (byte[]) inStream.ReadObject( "u16binary" ); Console.WriteLine("client: response: " + response.Length ); } catch( Exception e ) { Console.WriteLine( e.ToString() ); Console.Write( e.StackTrace.ToString() ); Console.WriteLine("Exception reading from Server"); } // tidy up networkStream.Close(); socketForServer.Close(); return response; }