示例#1
0
 private static bool Connect()
 {
     System.Console.WriteLine("Client created, initializing...");
     ServerConnection = new Connection();
     System.Console.WindowHeight = 50;
     System.Console.WindowWidth = 50;
     try
     {
         System.Console.WriteLine("Creating connection");
         ServerConnection = new Connection(LOCALHOST);
         System.Console.WriteLine("Connected, waiting for other players");
         RecieveInitialInformation();
     }
     catch (System.Net.Sockets.SocketException)
     {
         System.Console.WriteLine("Error while initializing game connection");
         System.Console.WriteLine("Connection to server not established; exiting");
         return false;
     }
     catch (Exception)
     {
         System.Console.WriteLine("Error while initializing game connection");
         System.Console.WriteLine("Wrong data recieved; exiting");
         return false;
     }
     return true;
 }
示例#2
0
 public void connectToServer()
 {
     try
     {
         connection = new Connection(listener.AcceptTcpClient());
         isConnected = true;
     }
     catch (SocketException e)
     {
         isConnected = false;
     }
     catch (InvalidOperationException e)
     {
         isConnected = false;
     }
 }