10

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?

1 Answer 1

13

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).

Sign up to request clarification or add additional context in comments.

1 Comment

As far as I understood, the proposed solution is to transfer the whole file, wait the transfer to be complete and then play the file. It is not really streaming, it is simply file copying. For applications where you need real time video the TCP solution works, but this UDP one does not.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.