What is the format for transferring data over TCP?

I would like some advice on what format to use to transfer data over TCP. Currently I have developed a simple textual protocol with line separators. I think I should be using something out there that already exists, such as XML, JSON, or XMPP?

What data formats are used by humans for transmission over TCP?

I would like to optimize for speed and bandwidth, but would rather use an existing standard than use my own.

+2


source to share


5 answers


You might want to look at Google Protocol Buffers or Apache Lean .



+4


source


Most of the time, people just declare a post with a layout that plays on both ends and uses that. It's only when you have more complex needs that you need to do something more interesting.



For variable length strings, I would most likely implement them as a series of lengths and then the length of the data bytes. In Cish languages, you could probably traverse without length using a null delimiter. Nothing more complicated than it really needs to be.

0


source


Depends on the type of data and who is using your data.

If you are writing your own client / server pair, then perhaps the best format is some sort of binary serialization. It is compact, easy to wire, and can be quickly remodeled.

If you are writing something for many consumers using different languages ​​... then I'm more worried about XML or JSON (depending on the size and complexity of your data).

XML is better suited for large, complex pieces of data.

JSON is better for smaller, more compact pieces of data.

0


source


The data key / value appearance assumes JSON , which is easier to work with.

Optimizing for speed and bandwidth is probably better handled outside of your application, layers 3 and 4 in the OSI model I would take a chance. One unit of optimization effort invested in these layers will probably give you more optimality than one unit of effort diving into the structure and coding of your data.

0


source


XML sounds like a good choice for your datatype - there are already many XML libraries out there (or your language might even have XML parsing built in).

Text based also makes it easier to debug things by hand, so one reason to avoid binary encodings on the wire.

0


source







All Articles