Simple protocol, which guy?

I have a simple server written in C. The main goal is to communicate with some business partners using a proprietary protocol. For this reason and several others, it should be written in C. I have a number of other processes, however written in other languages ​​(e.g. Python) that must communicate with the server (locally, on the same Linux server).

What are the best IPC internetworking options in this scenario? In particular, I believe that I am dealing with transport technologies: Unix domain sockets, named pipes, shared memory, ZeroMQ (Crossroads). I'm more interested in the best way to implement the protocol so that the C code is small and supported, but at the same time allows you to communicate with other languages.

Edit : there seems to be some kind of confusion. I am not interested in discussing the pros / cons of domain sockets, shared memory et. et al. I 'm interested in msgpack (thanks) and other technologies / approaches for implementing a wired protocol.

+7
source share
2 answers

It is difficult to optimize (= choose "best") when requirements are unknown. You state that your goal is to keep the C code “small and maintainable,” which apparently means you should look for a library. Perhaps msgpack through a local socket?

Also, your basic premise is that the server must be written in C, because you have your own protocol, it seems ... strange, at least.

+4
source

Edit: you need a “serialization structure”, i.e. something can turn a memory structure into a stream of bytes. The best candidates:

Pros / Cons:

Protocol Buffers

  • + Fast
  • + Simple version (which you will begin to love very much when you need to first make changes to your message format and to which you will curse before that)
  • - Solves many problems that you still do not know about. This makes the API a little weird. I assure you, there are very good reasons for what and how they do it, but sometimes you will be a little embarrassed.

I am not very good at MessagePack.

Finally:

Json

  • + Any language there can read and write JSON data.
  • + Human reading without tools
  • - somewhat slow
  • - format is very flexible, but if you need to make big changes, you need to find a strategy to find out what format (= which fields) the message has when you read it.

As for the transport level:

Pros / Cons:

Common memory

  • + The fastest option
  • - You need a second channel (for example, a semaphore) to tell another process that the data is now ready
  • - gets really ugly when you try to connect more than two processes
  • - Specific OS

Named Pipes

  • + Very easy to set up
  • + Pretty fast
  • - Allows only two processes to speak ... or, rather, one process to talk with the other in one direction. If you need bidirectional communication, you need some pipes

Sockets

  • + Pretty easy to set up
  • + Available for all and any languages
  • + Allows remote access (not all processes must be on the same machine)
  • + Two-way communication with one server and several processes.
  • - Slower than shem and pipes

ZeroMQ

  • + Like sockets, but better
  • + Modern API (not old static IPC / socket)
  • + Support for many languages ​​...
  • - ... but not all

If you can offer to try ZeroMQ, because it is a modern structure that solves many problems that you will encounter with older technologies.

If this fails, I will try the sockets. They are simple, well maintained and obedient.

+4
source

All Articles