TCP, how to send both binary and string data?

Hi, I’m building a networked collaboration tool where two users can talk and share mouse activities (like drawing). I’m assuming both users are in the same wifi network.

I was able to use OF’s TCP to send/receive either mouse data (in string format, using send() and received() ) or voice data (in binary format, using sendRawBytes() and receiveRawBytes() ). But I could not figure out how to send both of them together.

I also want to note that I’m sending and receiving the voice data in the audio threads (audioIn and audioOut) so the playback can be smooth. I know that another obvious solution is to just use Google Chat or Skype instead of trying to send voice data over TCP, but I really need the audio signal to do some post-processing.

Thank you. I’d appreciate any input or suggestions.

I see two possible solutions:

  1. Open two sockets on two different ports, one for each type of information, and that way there’s no confusion.

  2. If for some reason, you want to transmit both pieces of data TOGETHER, I suggest you create your own "format and transmit it with binary. For example: Have the word characters MOUSE and have them followed by the mouse input or the characters VOICE, followed by the size of the voice data in bytes, followed by that many bytes of data.

Hope it’s clear enough.

1 Like

Thank you, it was very clear.

also the main problem seems to be that you are using 2 threads, perhaps the easiest is to send the data from one thread to the other so everything comes out of one thread only. using an ofThreadChannel can make this really easy

i would recommend to take a look at ofxGstRTP, it can be a little complicated to install since it depends on gstreamer and you’ll probably need to use the nightly builds but it allows to send audio, video, osc and even kinect data in perfect sync over a local network and even the internet no matter if there’s no direct open ports in the routers.