Monday, 19 August 2013

How to stop the while(true) in socket in Java

How to stop the while(true) in socket in Java

I am using Java Socket programming. When i click the button Socket is
working perfectly. But Button other functions are not working. All are
disable
This is Main Class
JButton btnRemote = new JButton("Remote ");
btnRemote.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
ServerInitiator ser=new ServerInitiator();
ser.initialize(4444);
}
});
Socket Class
public static void main(String args[]){
String port = JOptionPane.showInputDialog("Please enter listening
port");
new ServerInitiator().initialize(5555);
}
public void initialize(int port){
try {
ServerSocket sc = new ServerSocket(port);
//Show Server GUI
drawGUI();
// drawGUI();
//Listen to server port and accept clients connections
while(true){
Socket client = sc.accept();
System.out.println("New client Connected to the server");
//Per each client create a ClientHandler
new ClientHandler(client,desktop);
}
} catch (IOException ex) {
ex.printStackTrace();
}
}

No comments:

Post a Comment