I can't seem to be able to use UDP or find any examples of how to use it in PyZMQ.
I want to be able to send a h264 stream. I was able to do that using TCP by using @nathancy answer on Python Opencv and Sockets - Streaming video encoded in h264.
But I can't seem to be able or find any examples of how to use UDP in PyZMQ
What is it that I need to do to send data with UDP instead of TCP for speed increase?
If a frame is lost, it is lost, I don't need to re send it. That is why I want use UDP
Q : What is it that I need to do to send data with UDP instead of TCP...?
A :
Well,
ZeroMQ has a way to use UDP-transport for Pragmatic General Multicast (PGM) protocol, be it either of ZeroMQ { pgm:// | epgm:// }
-transport-classes. Yet, caveats apply:
The
pgm
transport implementation requires access to raw IP sockets. Additional privileges may be required on some operating systems for this operation. Applications not requiring direct interoperability with other PGM implementations are encouraged to use theepgm
transport instead which does not require any special privileges.
So, for the ZeroMQ classical PUB / SUB
-data-flows, one can setup something like this :
//
// Connecting to the multicast address 239.192.1.1, port 5555,
// using the first Ethernet network interface on Linux
// and the Encapsulated PGM protocol
//
rc = zmq_connect( aMulticastOverUDP_socket, "epgm://eth0;239.192.1.1:5555" );
assert (rc == 0 && "____ Well, something went wrong on epgm:// connect" );
In Python, that might sound like:
#----------------------------------------------------- start Context()-engine
aContext = zmq.Context( nIoTHREADs )
#----------------------------------------------------- start Socket()-instances
aUdpPUB = aContext.socket( zmq.PUB )
#----------------------------------------------------- start settings
aUdpPUB.setsockopt( zmq.LINGER, 0 )
aUdpPUB.setsockopt( zmq...., ... )
...
#----------------------------------------------------- start serving
aUdpPUB.bind( "epgm://eth0;239.192.1.1:5555" )
...
#----------------------------------------------------- start dismantling
aUdpPUB.close()
aContext.term()
For fine-tuning the E2E performance, one has to tweak related Context()
-instances' zmq_setsockopt()
-parameters, to squeeze the transport on max