I’m programming a simple network chat with a Python server and a Java client. But one question came into my mind:
Which ‘network protocol’ should I use for communication? There are some possibilities for me:
- YAML: Nice to parse, problem: parsed objects contain language specific parts
- XML: Easy to parse, big overhead for simple tasks
- create an own ‘language’: Problems with escaping, but most flexible
So what is the best practice for this? Are there other alternatives?
Check JSON. It is compatible accross many languages (Python and Java included), and it is human readable. http://www.json.org/
If you plan to do Web development, and plan to use Javascript, then JSON might be a good choice as it was originally designed for Javascript. Moreover compared to YAML, using JSON in Python is as easy as writing:
import json(it is part of the standard library).You may have a look at the following page, comparing XML, JSON, and YAML. It seems they are differences in terms of encoding delay and memory used, that might guide your choice.