Skip to content

Commit 5c78e2e

Browse files
authored
SocketIO: Fix encoding and endless callbacks (#1283)
1 parent 3824ed0 commit 5c78e2e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/qz/communication/SocketIO.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ public String processSocketResponse() throws IOException {
6262
}
6363
}
6464
while(dataIn.available() > 0);
65-
66-
return new String(ArrayUtils.toPrimitive(fullResponse.toArray(new Byte[0])), encoding);
65+
if(fullResponse.size() > 0) {
66+
return new String(ArrayUtils.toPrimitive(fullResponse.toArray(new Byte[0])), encoding);
67+
}
68+
return null;
6769
}
6870

6971
public void close() throws IOException {

src/qz/utils/SocketUtilities.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ public static void setupSocket(final Session session, String UID, SocketConnecti
3030

3131
//TODO - move to dedicated options class?
3232
Charset encoding = StandardCharsets.UTF_8;
33-
if (!params.isNull("encoding")) {
34-
try { encoding = Charset.forName(params.getString("encoding")); }
35-
catch(JSONException e) { LoggerUtilities.optionWarn(log, "string", "encoding", params.opt("encoding")); }
33+
if (!params.isNull("options")) {
34+
JSONObject options = params.getJSONObject("options");
35+
36+
if (!options.isNull("encoding")) {
37+
encoding = Charset.forName(options.getString("encoding"));
38+
}
3639
}
3740

3841
try {

0 commit comments

Comments
 (0)