Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Practice: network communication [closed]

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?

like image 388
guerda Avatar asked Dec 17 '22 09:12

guerda


2 Answers

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.

like image 78
Mapad Avatar answered Dec 28 '22 22:12

Mapad


It may be a little bit heavyweight for your needs, but have you considered implementing XMPP protocol for your chat client?

If you do that, then your system could interoperate with Google Talk, Jabber, iChat, etc.

like image 26
Alnitak Avatar answered Dec 29 '22 00:12

Alnitak