public synchronized void sendCommand(final ServerCommand pServerCommand) {
if (pServerCommand == null) {
return;
}
try {
//byte array to write server command
ByteArrayOutputStream baosData = new ByteArrayOutputStream();
DataOutputStream osData = new DataOutputStream(baosData);
//byte array that will be used to write on socket
//this will contain length of ByteArrayData and then ByteArrayData
ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
DataOutputStream osOut = new DataOutputStream(baosOut);
//write command into osData byte array
pServerCommand.write(osData);
//write length of command into main byte array
osOut.writeShort(baosData.size());
//write command into main byte array
baosData.writeTo(baosOut);
OutputStream out = this.getSocket()
.getOutputStream();
//write main byte array on socket
byte[] data = baosOut.toByteArray();
out.write(data, 0, data.length);
out.flush();
} catch (IOException e) {
Log.pt("Exception when sending command", e.getMessage());
// Socket is possibly closed
}
}
That's not a bug, it's a feature.Quote:
hi,
i have a problem can someone please help me
this : Error: Exception when sending command: Socket closed
(9.0 client)
Code:public synchronized void sendCommand(final ServerCommand pServerCommand) { if (pServerCommand == null) { return; } try { //byte array to write server command ByteArrayOutputStream baosData = new ByteArrayOutputStream(); DataOutputStream osData = new DataOutputStream(baosData); //byte array that will be used to write on socket //this will contain length of ByteArrayData and then ByteArrayData ByteArrayOutputStream baosOut = new ByteArrayOutputStream(); DataOutputStream osOut = new DataOutputStream(baosOut); //write command into osData byte array pServerCommand.write(osData); //write length of command into main byte array osOut.writeShort(baosData.size()); //write command into main byte array baosData.writeTo(baosOut); OutputStream out = this.getSocket() .getOutputStream(); //write main byte array on socket byte[] data = baosOut.toByteArray(); out.write(data, 0, data.length); out.flush(); } catch (IOException e) { Log.pt("Exception when sending command", e.getMessage()); // Socket is possibly closed } }
This method isn't the problem of lag in-game since adding some primitive types into a byte array isn't something that takes enough time to produce lag.Quote:
i dont want use sendcommand when socket is closed because this is create a some lag in-game, can you help me for that?
<minimap typeID="91"/>