Server works once only
Posted on 2003-03-26
I've made a simple program in order to try and work out the problem with the real one. However, I can't seem to get around it. Help would be greatly appreciated.
There is a client and a server, both using swing (JApplet and JFrame respectively).
The client has a JCheckBox, a JTextField, and a JButton.
The server has a JLabel.
The idea is that the client selects, de-selects or leaves the JCheckBox alone. When he clicks on the JButton, a number - 0 or 1 - is sent to the server by the output stream, representing whether the checkbox is selected or not. The server checks the number, and sets the text of its JLabel to reflect whether the client's checkbox is selected. Having done that, it sends a 0 or 1 back to the client; as with the server, the 0 or 1 determines whether the checkbox is selected, and the JTextField's text is adjusted. So, the end result is that when the client presses the button, both the server and the client tell the user the state of the button.
It works the first time around. However, when the client presses the button a second time around, both sides' programs lock up completely. I'm certain it is something to do with the datastreams, but I can't determine what.
public void actionPerformed(ActionEvent action)
Socket client = new Socket(getCodeBase().getHost(), 3333);
DataOutputStream output = new DataOutputStream(client.getOutputStream());
DataInputStream input = new DataInputStream(client.getInputStream());
//[if it is selected]
//[if it isn't selected]
It's more or less the same on the client side (except for it being a socket instead of a serversocket etc.). Any ideas?