Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netcat streaming using UDP

I can get netcat to stream a video using TCP

  {server}  cat [movie].avi | nc [client ip address] 65535

  {client}  nc -l -p 65535 | mplayer -

i have tried using the -u command to send via UDP but this doesn't work

  {server}  cat [movie].avi | nc -u [client ip address] 65535

  {client}  nc -u -l -p 65535 | mplayer -

Any ideas?

like image 882
Dan1676 Avatar asked Nov 29 '11 11:11

Dan1676


1 Answers

There is a fundamental difference between streaming bytes with TCP and UDP...

  • TCP communicates an EOF when it sees the end of the byte-stream
  • UDP just stops sending data (i.e. it doesn't notify the other end of the data stoppage)

The consequences are that your TCP example works, but the UDP example doesn't because mplayer never knows when to process the bytes it is getting.

One way to solve this is with a timeout on both sides... First start your client with a timed finish (backgrounding the nc portion in a subshell so it won't block):

(nc -q 1 -u -l -p 65535 > [movie].avi&); sleep 10; fuser -k 65535/udp;\
    mplayer [movie].avi; rm [movie].avi

Next start your server... in this case, I show it pushing the file to 192.168.12.238 on udp/65535

(cat [movie].avi | nc -u 192.168.12.238 65535&); sleep 10; \
    fuser -n udp ,192.168.12.238,65535 -k

Finally, be sure you choose the timeout to be long enough to sequence the shell commands and finish the network transfer (which is normally rather quick, if you're on a wired ethernet LAN).

like image 183
Mike Pennington Avatar answered Sep 23 '22 05:09

Mike Pennington