lacraig2
lacraig2

Reputation: 655

Which protocol should I use for pyzmq?

I am working on a project where I have a client server model in python. I set up a server to monitor requests and send back data. PYZMQ supports: tcp, udp, pgm, epgm, inproc and ipc. I have been using tcp for interprocess communication, but have no idea what i should use for sending a request over the internet to a server. I simply need something to put in:

    socket.bind(BIND_ADDRESS)

DIAGRAM: Client Communicating over internet to server running a program

Upvotes: 2

Views: 1547

Answers (2)

Jason
Jason

Reputation: 13766

Any particular reason you're not using ipc or inproc for interprocess communication?

Other than that, generally, you can consider tcp the universal communicator; it's not always the best choice, but no matter what (so long as you actually have an IP address) it will work.

Here's what you need to know when making a choice between transports:

  1. PGM/EPGM are multicast transports - the idea is that you send one message and it gets delivered as a single message until the last possible moment where it will be broken up into multiple messages, one for each receiver. Unless you absolutely know you need this, you don't need this.
  2. IPC/Inproc are for interprocess communication... if you're communicating between different threads in the same process, or different processes on the same logical host, then these might be appropriate. You get the benefit of a little less overhead. If you might ever add new logical hosts, this is probably not appropriate.
  3. Russle Borogove enumerates the difference between TCP and UDP well. Typically you'll want to use TCP. Only if absolute speed is more important than reliability then you'll use UDP.

It was always my understanding that UDP wasn't supported by ZMQ, so if it's there it's probably added by the pyzmq binding.

Also, I took a look at your diagram - you probably want the server ZMQ socket to bind and the client ZMQ socket to connect... there are some reasons why you might reverse this, but as a general rule the server is considered the "reliable" peer, and the client is the "transient" peer, and you want the "reliable" peer to bind, the "transient" peer to connect.

Upvotes: 5

Russell Borogove
Russell Borogove

Reputation: 19057

Over the internet, TCP or UDP are the usual choices. I don't know if pyzmq has its own delivery guarantees on top of the transport protocol. If it doesn't, TCP will guarantee in-order delivery of all messages, while UDP may drop messages if the network is congested.

If you don't know what you want, TCP is the simplest and safest choice.

Upvotes: 0

Related Questions