Socket class freeze
Why does my program freeze up when i run this funtion on a click button event?
public void runServer()
{int counter = 1;
try {
server=new ServerSocket(4000,100);
while(true)
{
Chat.display.setText("waiting for connection\n");
connection=server.accept();
Chat.display.append("Connection "+counter+
"recieved from "+ connection.getInetAddress).getHostName());
output=new ObjectOutputStream(connection.getOutputStream());
output.flush();
input=new ObjectInputStream(connection.getInputStream());
Chat.display.append("\nGot I/O stream\n");
message="server>>connection successfull";
output.writeObject(message);
output.flush();
}
But when i run it from main like this it runs with no freeze
public static void main(String args[])
{
Chat ch = new Chat();
ch.runServer()
}
I Dont want it to run from main. i want to run it when i click a button.

