I need to send a small bit of data to a server application on a separate machine. Because of some problems I was having detecting a closed socket, I am now creating a new socket each time I want to send data. However, the problem is that when I shut down the server process, the next socket connection still succeeds. The flow is as follows:
1) Close() any streams, sockets, that are non-null 2) get new socket [ s = new Socket(host, post); ] 3) check isClosed(), isBound() and isConnected() to make sure socket is good 3) Initialize streams (PrintWriter and BufferedReader) 4) Send data [ printStream.println() ] 5) Check status with printStream.checkError()
The problem occurs like this: 1) Turn app on 2) Connect/Send data successfully (data is getting to app as can be seen by app's logfiles) 3) Close app 4) Try to get a new socket which *SUCCEEDS*. Unfortunately this application does not send any data back so that cannot be used to verify proper operation.
The interesting part that if step 4 is repeated in code with a 3 second delay, it connects twice to the 'ghost server'. However, if I do the entire process via the GUI (a jsp page), it fails on the second click (which triggers data to be sent to the server). The only difference here seems to be the fact that a different thread is being used.
If anyone can provide any help I would greatly appreciate it!