diff --git a/src/main/java/com/corundumstudio/socketio/protocol/PacketDecoder.java b/src/main/java/com/corundumstudio/socketio/protocol/PacketDecoder.java index cc00ae0f..73921d26 100644 --- a/src/main/java/com/corundumstudio/socketio/protocol/PacketDecoder.java +++ b/src/main/java/com/corundumstudio/socketio/protocol/PacketDecoder.java @@ -150,10 +150,10 @@ private Packet decode(ClientHead head, ByteBuf frame) throws IOException { final int separatorPos = frame.bytesBefore((byte) 0x1E); final ByteBuf packetBuf; - if (separatorPos != -1) { + if (separatorPos > 0) { // Multiple packets in one, copy out the next packet to parse packetBuf = frame.copy(frame.readerIndex(), separatorPos); - frame.readerIndex(separatorPos + 1); + frame.readerIndex(frame.readerIndex() + separatorPos + 1); } else { packetBuf = frame; } diff --git a/src/test/java/com/corundumstudio/socketio/transport/HttpTransportTest.java b/src/test/java/com/corundumstudio/socketio/transport/HttpTransportTest.java index 7b1d1e64..44261559 100644 --- a/src/test/java/com/corundumstudio/socketio/transport/HttpTransportTest.java +++ b/src/test/java/com/corundumstudio/socketio/transport/HttpTransportTest.java @@ -174,9 +174,10 @@ public void testMultipleMessages() throws URISyntaxException, IOException, Inter final ArrayList events = new ArrayList<>(); events.add("420[\"hello\", \"world\"]"); events.add("421[\"hello\", \"socketio\"]"); + events.add("422[\"hello\", \"socketio\"]"); postMessage(sessionId, events.stream().collect(Collectors.joining(packetSeparator))); final String[] responses = pollForListOfResponses(sessionId); - Assert.assertEquals(responses.length, 2); + Assert.assertEquals(responses.length, 3); } /**