So this problem is driving me crazy. I have one little program where I open a Socket, send a byte for 'P' and then do a readLine...this works perfectly fine 100% of the time.
I now have a different program where I've put the bit of working code to get the data from a server (from my other program) which is part of a much larger system. I SEEM to do the send ok (no exceptions), but as soon as the readLine() gets called, I get the following:
java.net.SocketException: Software caused connection abort: recv failed at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(Unknown Source) at sun.nio.cs.StreamDecoder.readBytes(Unknown Source) at sun.nio.cs.StreamDecoder.implRead(Unknown Source) at sun.nio.cs.StreamDecoder.read(Unknown Source) at java.io.InputStreamReader.read(Unknown Source) at java.io.BufferedReader.fill(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source)
Here's the two methods that get called (Note: getOutputStream() and getInputStream() get the i/o stream of the open socket:
So in one case, it works fine...in the other case, it never works...with practically the exact same code. I have a feeling I'm missing something blatantly obvious, but I don't know what to look for or where to start. Any ideas?
Using readLine() with a socket is a bad idea since it uses the current platform's EOL indicator and different platforms have different EOL indicators. For example, if you're running your program on a Windows computer, the EOL is "\r\n" but a Unix server is going to send "\n" by default.
I finally figured it out (I guess a weekend of not staring at it in frustration helps). It turns out that it was a Threading issue...I had created the socket in one thread and sent it into another one.