I’m attempting to write song data to a socket however after approximately 66338 bytes the following exception is thrown:
E/ ( 1016): Connection reset by peer
E/ ( 1016): java.net.SocketException: Connection reset by peer
E/ ( 1016): at org.apache.harmony.luni.platform.OSNetworkSystem.writeSocketImpl(Native Method)
E/ ( 1016): at org.apache.harmony.luni.platform.OSNetworkSystem.write(OSNetworkSystem.java:723)
E/ ( 1016): at org.apache.harmony.luni.net.PlainSocketImpl.write(PlainSocketImpl.java:578)
E/ ( 1016): at org.apache.harmony.luni.net.SocketOutputStream.write(SocketOutputStream.java:59)
E/ ( 1016): at com.myprogram.StreamProxy.processRequest(StreamProxy.java:307)
E/ ( 1016): at com.myprogram.StreamProxy.run(StreamProxy.java:145)
E/ ( 1016): at java.lang.Thread.run(Thread.java:1096)
This only happens with certain songs and if one song does it all of the songs in the entire album do the same thing. I’m wondering if it has something to do with the header information for the song?
Any suggestions on how to debug or fix this would be greatly appreciated. Thanks.
EDIT: Here’s the code that is reading from an InputStream and writing back out to a socket. The code is pretty straight forward so I’m not really sure why it would be crashing unless the connection is being closed on the receiving end. (Note: this is only psuedocode, but gives the general idea)
InputStream data = realResponse.getEntity().getContent();
Socket socket = new ServerSocket(port, 0, InetAddress.getByAddress(new byte[] {127,0,0,1}));
socket.setSoTimeout(5000);
port = socket.getLocalPort();
Socket client = socket.accept();
...some code...
byte[] buff = new byte[1024 * 50];
while (isRunning && (readBytes = data.read(buff, 0, buff.length)) != -1) {
client.getOutputStream().write(buff, 0, readBytes);
}
Also, could this have anything to do with the socket buffer filling up? Especially since it seems to crash at 64k every time.
The server process on the other side likely had an abnormal termination (ex. SIGKILL). That would cause a connection rest.