An established connection was aborted by the software in your host machine

I get this error while sending thread is sending data:

java.io.IOException: An established connection was aborted by the software in your host machine

It isn’t thrown right away, first couple of messages get sent and my test server receives them and print them (actually that’s all it does).
I catch it and print it so I don’t exactly know on what part of code it happened (and how to print that also?). It’s hard to start debuging when I don’t know much, or anything :slight_smile:

I catch it and print it so I don’t exactly know on what part of code it happened

Huh?

try{…}catch(Exception e){e.printStackTrace();}

shows you where it happens.

tnx, I was just using println(e).

Anyway I started it again and this time it works fine ??? :stuck_out_tongue: … Before I tried it like 5-6 times, so don’t know what actually happened between except me switching to printStactTrace(). Tnx for your help oNyx, I hope it stays this way.

Found out why exception was being thrown. Has nothing to do with my packet sender, but in my test server I had bug while reading buffer. It was set that if it reads less then 1 bytes then it terminates connection. It shuold have been less then zero. Still don’t know why program even reads a buffer second time if it has 0 bytes (assuming it read everything first time)… stupid.

Correct code to put for reading:


while ((bytes_read = sc.read(read_buffer)) > 0) { ... }