0

As I hate reinventing the wheel, I wonder if there are any commonly used packaged out there for doing hte simple job of communicating (key,value) pairs of data betweeen two network endpoints (probably TCP/IP is the most likely carrier). I would like something that works in any environment, which for me means Unix/Linux-style socket API written in C or maybe C++. Java is nice, but only Java makes it hard to integrate into binary programs. C# etc. is out due to the need to be portable to Linux hosts.

Is there such a beast?

0

5 Answers 5

5

Consider using JSON? There are libraries available for most programming languages.

1
  • JSON is easy to decode in almost ANY language.. even if the Linux peer just saves it for something else to worry about. +1 , Good answer.
    – Tim Post
    Feb 27, 2009 at 15:41
2

Google has a data interchange format called Procotol Buffers you may want to consider.

4
  • That also looks like a good candidate... except that maybe the need to declare things is a problem if you want to build a generic receiver end that muxes out data to various receivers. And you don't want to rebuild all every time. Oct 29, 2008 at 7:32
  • I would guess that Protocol Buffers is (or can be made) much more efficient than JSON or YAML.
    – JesperE
    Oct 29, 2008 at 9:42
  • Can anyone say over-engineering? Feb 27, 2009 at 16:43
  • Yes. MSI is over-engineered. Corba is over-engineered. Protocol Buffers is not.
    – JesperE
    Feb 27, 2009 at 20:00
1

Socket-level APIs are the way to go if you want complete portability. I suppose there are packages for each language that can do the proper bit-molding in both directions, but I'm not aware of any single package that is ported to all these languages.

1

netstrings are an old solution if you would like to have minimal overhead.

2
  • Netstrings seems odd to me. The guy wrote a short paper describing how every C programmer transmits strings and then claims that they will secure the web? Am I missing something? Feb 27, 2009 at 16:40
  • If you know the length of a string before you begin to process it you can prevent one major security exploit: buffer overruns. Feb 27, 2009 at 18:03
0

There's also bencoding. There's probably libraries (torrent libraries) that will parse it easily enough.

Not the answer you're looking for? Browse other questions tagged or ask your own question.