Socket.IO vs. Twisted [closed]

2024/7/27 15:45:05

My idea is to build a simple chat application for iOS and Android. In any case, my question is related to the server-side. The best option to do a chat application, from what I've read, is to build a socket. Referring to the database, my intention is to use MySQL, which may also be important to take into account in order to choose one of the possibilities.

My question is, in terms of scalability, speed and security, which is the best option: building a socket with Python using Twisted or with NodeJS using Socket.IO?

I guess that there may be other possibilities to build an efficient socket, but by now I'm considering this two. I'd really appreciate it if you could give me some advice.

Answer

Comparing Twisted and Socket.io is comparing apples to a truck carrying apples. Twisted is a library that provides event oriented programming functionality to Python. In javascript that's merely javascript itself (be it node.js or a web browser or even rhino).

A more apt comparison is to compare Socket.io on node.js with Socket.io on Python. While there is one main implementation of a socket.io server on node there are several for Python:

  • https://github.com/MrJoes/tornadio

  • https://github.com/abourget/gevent-socketio

  • https://github.com/stephenmcd/django-socketio

(taken from the socket.io wiki: https://github.com/learnboost/socket.io/wiki)

You can even implement your own socket.io in Python using Twisted if you want. The socket.io protocol is documented here: https://github.com/LearnBoost/socket.io-spec. But that would defeat the purpose of socket.io - it abstracts away low level details of real time web communications and allows you to concentrate on writing your business logic.

On the client side you'd deploy the same socket.io script to the browser regardless of what language you decide to write the server in.

With regards to which language to choose: my rule of thumb is choose the language you're most comfortable with. You're going to have enough problems debugging your business logic. Don't complicate it by using an unfamiliar language.

Both languages are battle hardened (yes, even node.js which is surprising considering how young it is). Python for example is used in production on such high traffic services as Dropbox. Node is currently in use on such high traffic services as LinkedIn mobile.

https://en.xdnf.cn/q/73379.html

Related Q&A

How do I make Django ManyToMany through queries more efficient?

Im using a ManyToManyField with a through class and this results in a lot of queries when fetching a list of things. Im wondering if theres a more efficient way.For example here are some simplified cla…

How do I structure my Python project to allow named modules to be imported from sub directories

This is my directory structure:Projects+ Project_1+ Project_2- Project_3- Lib1__init__.py # emptymoduleA.py- Tests__init__.py # emptyfoo_tests.pybar_tests.pysetpath.py__init__.py # emptyfoo.pybar.p…

Plotly - Adding Scatter Geo points and traces on top of Density Mapbox

I am trying to add a Scattergeo trace or overlay on top of a white-bg density mapbox to get a heat map over a generic USA states outline. The reason for my use of scattergeo is Id like to plot a star s…

Removing items randomly from a dictionary

How do I remove random items from a dictionary in Python?I have to remove a specified number of items from a dictionary and so I tried to use dict.popitem which I thought was random, but it is seems i…

Requests-html results in OSError: [Errno 8] Exec format error when calling html.render()

I am using requests-html and trying the render function, with little success. When I run this script using python3.8 #!/usr/bin/python3 from requests_html import HTML file = "scrape/temp_file2.ht…

Python setuptools: packaging the root directory (no subdirectory per package wanted)

I need to write a package into a repository, but it is a small quick package, so I dont see the need to put files into a subdirectory. I simply want: import mypkg.module1with directory structure root_f…

ImportError when trying to import python module in SublimeText2

Im new to SublimeText2. So far I have found it excellent, but I just came across a problem I did not manage to solve. Im trying to import a Python module, mechanize, into my script. However, whenever a…

sendfile() failed (32: Broken pipe) while sending request to upstream nginx 502

I am running Django, uwsgi, ngix server. My server works fine for GET, POST requests of smaller size. But when POSTing requests of large size, nginx returns 502: nginx error.log is: 2016/03/01 13:52:1…

Python introspection - how to check current module / line of call from within function

I have a function:# utils.py def hello(name=World):# Detect where Im being called from.print(Hi, %s. You called this from %s at line # %d. % (name, mod, lineno))# ``mod`` and ``lineno`` on previous lin…

Flask blueprints with gevent working outside of application context

I am trying to send emails asynchronously with in Flask with gevent via flask-mail. I am getting "working outside of application context". I am aware of with app.app_context() but I cannot ge…