Skip to content

TCP packets not parsed because of frame length prefix #82

Open
@arlomedia

Description

@arlomedia

I'm trying to use the TCP support added by @daveyarwood, but my server listener was only calling the handleBadData() function, with the error "No '44' present after the address, but there is still more data left in the message."

I dug into the OSCParser class and realized that it's not handling the first four bytes of the message, which is a prefix that provides the message size. If JavaOSC doesn't need that, I guess it should ignore or discard it somehow.

In my local copy of OSCParser, I edited the convertMessage function to rename the rawInput argument to rawInputWithLength, then added these lines at the start of the function:

ByteBuffer rawInput = null;
if (rawInputWithLength.limit() > 4) {
	rawInput = ByteBuffer.allocate(rawInputWithLength.limit() - 4);
	for(int i = 4; i < rawInputWithLength.limit(); i++) {
		rawInput.put(i - 4, rawInputWithLength.get(i));
	}
} else {
	rawInput = rawInputWithLength;
}

This discards the length prefix and then the parsing works correctly.

However, this should only happen with TCP packets, and I plan to use UDP for other functions in the future. So I also had to edit OSCPortInBuilder and OSCSerializerAndParserBuilder so the OSCParser would know what network protocol it's used with. In OSCPortInBuilder.build(), after

parserBuilder = new OSCSerializerAndParserBuilder();

I added

parserBuilder.setNetworkProtocol(networkProtocol);

And in OSCSerializerAndParserBuilder, I added

public void setNetworkProtocol(NetworkProtocol networkProtocol) {
	this.properties.put("networkProtocol", networkProtocol);
}

Then the new code in OSCParser.convertMessage() can check the protocol:

if ((properties.get("networkProtocol") == NetworkProtocol.TCP)&&(rawInputWithLength.limit() > 4)) {

Let me know if I have misdiagnosed the problem or if there's a better way to solve it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions