public void run()
        {
            try{
                sock = new UTF8Socket(ip);
            }
            catch (SocketException e) {
                gui.DisplayMessage("Error: could not connect to server. Please restart program.");
                return;
            }

            String response;

            sock.SendMessage(chatroom);
            response = sock.ReceiveMessage();
            if (response != "ACCEPTED")
            {
                Console.WriteLine("chatroom rejected.");
                throw new RoomNameException("Room " + chatroom + " does not exist. Please restart the program");
            }

            sock.SendMessage(username);
            response = sock.ReceiveMessage();

            if (response != "ACCEPTED")
            {
                Console.WriteLine("username rejected");
                throw new UserNameException("Username " + username + " is already taken. Please restart the program");
            }

            String message;

            Console.WriteLine("About to enter main loop");
            Console.WriteLine("Just entered main loop");

            // The main loop
            while (true)
            {
                try
                {
                    message = sock.ReceiveMessage();
                }
                catch (Exception e)
                {
                    gui.DisplayMessage("Connection to server has been broken. Please make sure server is running and restart this program.");
                    return;
                }
                Console.WriteLine("Just received message " + message);
                gui.DisplayMessage(message);
            }
        }
Example #2
0
 public void display()
 {
     win.DisplayMessage(message);
 }