My program listens for only one connection once ... the program just gets stuck in clientSocket = serverSocket.accept () if the client does not connect. I mean, I can't even interrupt him by closing the window. I cannot click any of my buttons in a frame, etc.
I used this code the same way as in my other programs, but it worked perfectly (I can click on the text fields and buttons and elements and enter values in them, for this it just hangs there until the client connects, maybe 't even go out).
public void runServer() {
try {
serverSocket = new ServerSocket(PORT_NUMBER, 20);
clientSocket = serverSocket.accept();
taDisplay.append("Client connected!");
lblPlayingTo.setText("Playing to: " + objective);
socketIn = new DataInputStream(clientSocket.getInputStream());
socketOut = new DataOutputStream(clientSocket.getOutputStream());
socketOut.writeUTF(serverName);
clientName = socketIn.readUTF();
lblEastScore.setText(clientName + ": " + eastScore.getScore());
} catch (IOException e) {
System.out.println(e);
taDisplay.append("Could not listen on port: " + PORT_NUMBER + ".\n");
}
}
I deleted all my code except this one (below), but I still get the same “freeze” problem
setTitle(title);
setSize(sizeW, sizeH);
setVisible(visibility);
setResizable(resizability);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addKeyListener(new MyKeyAdapter());
addMouseListener(new MyMouseAdapter());
c = getContentPane();
c.setLayout(new BorderLayout());