Reputation: 740
My mmorpg game server has a feature that has finally surpassed the 65535 length limit of sending "string updates" to the client. I was using the readUTF() and writeUTF() methods. I have since replaced them with:
CLIENT reading:
//incommingReply = GameActivity.commandIn.readUTF(); //65535 length limit
int length = GameActivity.commandIn.readInt();
byte[] data = new byte[length];
GameActivity.commandIn.readFully(data);
incommingReply = new String(data,"UTF-8");
SERVER writing:
//commandOut.writeUTF(request); //65535 length limit
byte[] b = request.getBytes("UTF-8");
commandOut.writeInt(b.length);
commandOut.write(b);
commandOut.flush();
Ever since changing, players are experiencing more disconnections due to "java.net.SocketException: Software caused connection abort". I am struggling to troubleshoot this. Is there a better way to send long Strings back and forth?
Addendum (other pertinent code):
GameActivity.sC = (SSLSocket) factory.createSocket();
GameActivity.sC.setSoTimeout(connectTimeout);
GameActivity.sC.connect(new InetSocketAddress(GameActivity.PROD_IP, GameActivity.PROD_PORT), connectTimeout);
...
GameActivity.commandIn = new DataInputStream(GameActivity.sC.getInputStream()); //create input-stream for a command socket
GameActivity.commandOut = new DataOutputStream(GameActivity.sC.getOutputStream()); //create output-stream for a command socket
Stack Trace:
E MCR Exception
E Exception: java.io.EOFException
E stack trace:
java.io.DataInputStream.readFully(DataInputStream.java:205)
java.io.DataInputStream.readInt(DataInputStream.java:394)
com.kisnardonline.kisnardonline.MyCommandReceiver.run(MyCommandReceiver.java:251)
java.lang.Thread.run(Thread.java:1012)
edit2 - changing to readObject() has not solved the problem
Upvotes: 0
Views: 102