Listing 15.6 Communicating with a Remote Server
// Get the stream
Stream s;
try
{
s = client.GetStream();
}
catch (InvalidOperationException exc)
{
Console.WriteLine(“Cannot connect to {0}: {1}”,
gameServer, exc.Message);
return;
}
Console.WriteLine( “Connected to game server” );
string response = GetResponse(s);
Console.WriteLine( “Response\r\n--------\r\nCode: {0} Message: {1} “,
GetResponseCode(response), GetResponseData(response));
// connected begin game
StartGame( s );
client.Close();
// Wait for user response to exit
Console.WriteLine(“Press Return to exit”);
Console.Read();
client.Close();
}