I've got a mod which some of my users tell me they get disconnected from multiplayer servers randomly when by this error message:
The only thing I can think that is doing this is that my mod contacts my web server to update the user's statistics so they can check on the website. It makes a simple GET request via HttpUrlConnection as shown below, in a different thread, so it doesn't freeze the game:
public static JsonObject sendGETRequest(String urlString) throws SocketTimeoutException {
try {
System.out.println("Sending request to: " + urlString);
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/json");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setConnectTimeout(3000);
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
int cp;
while ((cp = reader.read()) != -1) {
sb.append((char) cp);
}
String output = sb.toString();
JsonObject json = new JsonParser().parse(output).getAsJsonObject();
connection.getInputStream().close();
return json;
} catch (SocketTimeoutException e){
throw e;
} catch (IOException e){
e.printStackTrace();
}
return null;
}
The IO exception shows this in the console:
[22:36:48] [Netty Client IO #0/ERROR]: NetworkDispatcher exception
java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.read0(Native Method) ~[?:1.8.0_51]
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43) ~[?:1.8.0_51]
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223) ~[?:1.8.0_51]
at sun.nio.ch.IOUtil.read(IOUtil.java:192) ~[?:1.8.0_51]
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380) ~[?:1.8.0_51]
at io.netty.buffer.UnpooledUnsafeDirectByteBuf.setBytes(UnpooledUnsafeDirectByteBuf.java:446) ~[UnpooledUnsafeDirectByteBuf.class:4.0.23.Final]
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:881) ~[AbstractByteBuf.class:4.0.23.Final]
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:225) ~[NioSocketChannel.class:4.0.23.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:119) [AbstractNioByteChannel$NioByteUnsafe.class:4.0.23.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511) [NioEventLoop.class:4.0.23.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) [NioEventLoop.class:4.0.23.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) [NioEventLoop.class:4.0.23.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) [NioEventLoop.class:4.0.23.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) [SingleThreadEventExecutor$2.class:4.0.23.Final]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_51]
Which isn't very helpful from what I can see.
Any help would be greatly appreciated. Also I'm not saying that the connection is the problem but that's all I can suspect. I've now printed stuff before it makes the connection to find out if it was that but I'd have to push the update to users to find out and I don't want to have them download a new update just to see if it could be this bug.