• Post Reply Bookmark Topic Watch Topic
  • New Topic

SocketException on a readLine  RSS feed

 
Eric Chang
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eric Chang
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!