Skip to content

Commit

Permalink
SocketIO: Fix encoding and endless callbacks (#1283)
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Jul 24, 2024
1 parent 3824ed0 commit 5c78e2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/qz/communication/SocketIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ public String processSocketResponse() throws IOException {
}
}
while(dataIn.available() > 0);

return new String(ArrayUtils.toPrimitive(fullResponse.toArray(new Byte[0])), encoding);
if(fullResponse.size() > 0) {
return new String(ArrayUtils.toPrimitive(fullResponse.toArray(new Byte[0])), encoding);
}
return null;
}

public void close() throws IOException {
Expand Down
9 changes: 6 additions & 3 deletions src/qz/utils/SocketUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ public static void setupSocket(final Session session, String UID, SocketConnecti

//TODO - move to dedicated options class?
Charset encoding = StandardCharsets.UTF_8;
if (!params.isNull("encoding")) {
try { encoding = Charset.forName(params.getString("encoding")); }
catch(JSONException e) { LoggerUtilities.optionWarn(log, "string", "encoding", params.opt("encoding")); }
if (!params.isNull("options")) {
JSONObject options = params.getJSONObject("options");

if (!options.isNull("encoding")) {
encoding = Charset.forName(options.getString("encoding"));
}
}

try {
Expand Down

0 comments on commit 5c78e2e

Please sign in to comment.