Hi
I am working on a project at the moment. In summary:
-
I have one device (client) streaming audio via TCP/IP. It samples a 16 bit number (the amplitude) from a sensor.
-
The 16 bit number is then split into 2 bytes (because TCP/IP can only send in bytes) and sent over TCP/IP. So, for example, the data looks like this:
[Byte 1][Byte 2][Byte 1][Byte 2]...
- I have another device (server) which collects and processes the data - it effectively joins the bytes back up to get a 16 bit number.
The problem is ensuring that the server knows which bytes are in pairs (otherwise it may join the wrong bytes). The server may start listening after the client sends its first data so we cannot rely upon the first byte received as being the first byte in a pair.
I initially tried to solve this through TCP packets - effectively the client sends a packet of bytes where the first byte in the packet is guaranteed to be the first in a byte pair. But this doesn't work as it seems that TCP/IP libraries don't expose specific packets but only a stream of bytes.
Another solution is to use a delimiter between a large group of bytes (and then just wait until a delimiter is received so we know the next byte is byte 1 in a pair). I guess that means I'd have to set a byte aside with a value of somewhere in 0 - 255 to act as a delimiter? The problem with this approach, as I see it, is that one byte in a pair might happen to be the delimiter.
I'm finding this surprisingly difficult to solve so grateful for any thoughts. I'd like to keep it as simple as possible so ideally it'd all be one way (client to server) rather than sending acknowledgements back etc.
Thanks