klingtnet / rosc

An OSC library for Rust.
Apache License 2.0
173 stars 25 forks source link

Support TCP #19

Closed wvengen closed 2 years ago

wvengen commented 3 years ago

When working with TCP, the OSC spec mentions:

In a stream-based protocol such as TCP, the stream should begin with an int32 giving the size of the first packet, followed by the contents of the first packet, followed by the size of the second packet, etc.

I've had much trouble with rosc to use TCP, reading this little line in the spec I finally understand. Is it true that rosc doesn't implement this right now, and if so, would this be a good idea to have?

klingtnet commented 3 years ago

Given the signature of decode and encode rosc is actually transport agnostic since it consumes and produces slices of bytes. I guess the spec proposes to send the size of each packet when using TCP in case you want to send more than one OSC package/message over one TCP connection. It would likely be beneficial if rosc would provide some higher level networking abstractions but I lost track of how one is now doing proper networking with Rust when the whole asyncio thing happenend.

wvengen commented 3 years ago

Thanks for your response! I understand you've left out the networking part from rosc, I think that's fine. Someone else could provide a crate integrating rosc with a certain approach to networking. The existing examples here are helpful already for people wanting to use this.

Perhaps something like fn decode_tcp(msgs: &[u8]) -> Result<Vec<OscPacket>> and fn encode_tcp(packets: &Vec<OscPacket>) -> Result<Vec<u8>> would still be useful. (Though I'm not sure if it should be &Vec<OscPacket> or Vec<&OscPacket>.)

klingtnet commented 3 years ago

Perhaps something like fn decode_tcp(msgs: &[u8]) -> Result<Vec> and fn encode_tcp(packets: &Vec) -> Result<Vec> would still be useful. (Though I'm not sure if it should be &Vec or Vec<&OscPacket>.)

Yes, this would be helpful when interacting with other OSC implementations over TCP which follow the spec closely. Would you mind to contribute an implementation of those two functions? I can implement this as well but cannot guarantee when I will find the time to do that.

klingtnet commented 2 years ago

This got finally resolved with #21 , but there is no release yet. A proper release will follow as soon as we removed the dependency on the regex crate.