1

So, I'm doing a simple experiment with netcat where you can set up a voice call. Here are the commands I'm using.

server: arecord | netcat -l 10000 | aplay

client: arecord | netcat localhost 10000 | aplay

My issue here is that when the server starts a couple seconds before the client connects, the voice is delayed from the server. I am wondering how I can remove this delay. I'm pretty sure I just need to set some values in netcat, but I'm not sure which ones to set.

I have used UDP and TCP. Both don't make a difference.

  • Maybe use socat rather than netcat? – DopeGhoti Aug 9 '16 at 19:00
1

I would suspect your shell buffers arecord output before netcat is able to pass it further (which is when the client connects). To confirm, try:

arecord | pv | netcat -l 10000 | aplay

In my Ubuntu pv shows that arecord produces at least about 60 KiB of output (it takes about 8 seconds) even if there is no connection to netcat. You may suspect this buffer is implemented by pv but it does not depend on pv -B option, so I think it's the shell's buffer for the pipe.

I tried with stdbuf and unbuffer (the latter from expect-dev package in my Ubuntu) but the results were unsatisfying.

I achieved significant improvement when I used dd to flush enough data on the client side:

arecord | netcat localhost 10000 | { dd bs=100K count=1 iflag=fullblock of=/dev/null; aplay; }

In my case 100K was enough; your millage may vary. Note that you will have to wait several seconds for dd to finish if you run the command too soon (before the buffer is full on the server side) or if the bs=… parameter is way too big.

  • There's also -I for nc TCP receive buffer, and -O for send. – Tomasz Aug 9 '16 at 22:09
0

When using TCP, the connection is "guaranteed" not to lose data. In your case you probably don't want this, as the only way your client and server can avoid losing data is to queue it pending delivery.

With two systems you can switch to using UDP. Since this is connectionless you don't get your first packets queued, but they do get discarded. I can't test this out at the moment but I would suggest you try this:

Server on system 1

arecord | nc -u -l -p 10000 | aplay

Client on system 2

arecord | nc -u system1 10000 | aplay
  • I had already tried udp. – SpecialBomb Aug 9 '16 at 19:37
  • 1
    @SpecialBomb please update your question to explain this, and what (presumably) didn't work – roaima Aug 9 '16 at 19:42
  • @SpecialBomb so please update your answer, because roaima is right, and anyone reading your question will say the same to use UDP. – FarazX Aug 9 '16 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.