Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suggestion Needed - Networking in Python - A good idea?

I am considering programming the network related features of my application in Python instead of the C/C++ API. The intended use of networking is to pass text messages between two instances of my application, similar to a game passing player positions as often as possible over the network.

Although the python socket modules seems sufficient and mature, I want to check if there are limitations of the python module which can be a problem at a later stage of the development.

What do you think of the python socket module :

  1. Is it reliable and fast enough for production quality software ?
  2. Are there any known limitations which can be a problem if my app. needs more complex networking other than regular client-server messaging ?

Thanks in advance,

Paul

like image 702
Paul Avatar asked Dec 09 '22 19:12

Paul


2 Answers

Check out Twisted, a Python engine for Networking. Has built-in support for TCP, UDP, SSL/TLS, multicast, Unix sockets, a large number of protocols (including HTTP, NNTP, IMAP, SSH, IRC, FTP, and others)

like image 152
Yancy Avatar answered Dec 27 '22 21:12

Yancy


Python is a mature language that can do almost anything that you can do in C/C++ (even direct memory access if you really want to hurt yourself).

You'll find that you can write beautiful code in it in a very short time, that this code is readable from the start and that it will stay readable (you will still know what it does even after returning one year later).

The drawback of Python is that your code will be somewhat slow. "Somewhat" as in "might be too slow for certain cases". So the usual approach is to write as much as possible in Python because it will make your app maintainable. Eventually, you might run into speed issues. That would be the time to consider to rewrite a part of your app in C.

The main advantages of this approach are:

  1. You already have a running application. Translating the code from Python to C is much more simple than write it from scratch.
  2. You already have a running application. After the translation of a small part of Python to C, you just have to test that small part and you can use the rest of the app (that didn't change) to do it.
  3. You don't pay a price upfront. If Python is fast enough for you, you'll never have to do the optional optimization.
  4. Python is much, much more powerful than C. Every line of Python can do the same as 100 or even 1000 lines of C.
like image 43
Aaron Digulla Avatar answered Dec 27 '22 23:12

Aaron Digulla