package chat; import java.io.IOException; import java.net.Socket; import java.net.UnknownHostException; import javax.swing.JOptionPane; public class Client { public static void main(String[] args) { int port = 0; while(port < 1024 || port > 49151) { String response = JOptionPane.showInputDialog("Enter port: "); try { port = Integer.parseInt(response); } catch(NumberFormatException e) { } if(port < 1024 || port > 49151) JOptionPane.showMessageDialog(null, "Invalid port number entered.", "Invalid Port!", JOptionPane.ERROR_MESSAGE); } Socket socket = null; while(socket == null) { String address = JOptionPane.showInputDialog("Enter IP address: "); try { socket = new Socket(address, port); } catch (IOException e) { JOptionPane.showMessageDialog(null, "Invalid IP address or no server listening.", "Invalid Address!", JOptionPane.ERROR_MESSAGE); } } new Communicator(socket); } }