How to integrate python-socketio events with Pyramid views? - pyramid

I am working on a Pyramid python application which employs python-socketio to communicate with the frontend, but I find no information about how best to integrate the my Pyramid views and models with socket.io calls.
I adapted python-socketio Flask example to use Pyramid (and it works): https://github.com/pascalin/python-socketio/blob/main/examples/server/wsgi/pyramid_app.py
But even when Pyramid and socket.io calls coexist, the socket.io server does not check for the security policy which Pyramid is employing, and I would like to be able to emit socket.io events based on Pyramid events and views. Do you have any suggestions about how to take this simple example in the direction I want?
Thank you!

Related

Sanic with websocket and SocketIO. Which one to use?

Using Sanic, you can handle websockets connections using #app.websocket('/socket.io/') but the protocol used in Socket.io is specific.
Python has Python-Socketio as a module to handle Socket.Io specific communications, but they recommend to use the code like this :
sio = socketio.AsyncServer(async_mode='sanic')
app = Sanic()
sio.attach(app)
#sio.on('connect')
def on_connect():
...
So, which one should be used? Should we implement SocketIo protocol inside #app.websocket from Sanic, or should we ignore this and directly use the implementation from SocketIo?
I'm asking for both rapidity and best practice here. If the best decision is to go with #app.websocket, how can we set up Socket.io inside the Sanic handler?
The Socket.IO protocol is very complex, it will take you a decent amount of time to implement it all manually in the websocket route. Also note that Socket.IO uses the same route for HTTP and WebSocket, something that I understand it is not possible to do (easily, at least) with Sanic.
The python-socketio package integrates with many frameworks, including Sanic to implement all the details of the Socket.IO protocol.

What is the best framework and difference of nodejs framework

These days I try to develop real time application using nodejs.
That application want to update the dashboard according to api data.
I installed express and faye and try to compare what is the best and what are the differences of that two.
As I know express is a node base framework and faye is a subscriber/publisher based one.
But I think both are almost same and anyone can help me to identify the differences?
What is fast and what can be done using the frameworks like that ?
Thanks in advance.
They are not very comparable. If you want to create a real-time application, you will probably need to use both.
Express is a web framework. You will need it to serve and handle HTTP requests and responses. It will help you handle things like url routing, request/response handling middleware, interfacing with template engines, etc... Express is as fast as you'll get.
Faye is a pub sub messaging system- It will not be capable of handling standard HTTP requests and responses. You may be able to implement a live stream of the data using Faye, however, you will still have the need to serve up your client side application using Express.
I would also look into Socket.io as an alternative to Faye- in addition to Express.

Node.js with socket.io

I am looking to build an web application using node.js and possibly socket.io but I am having a lots of confusion regarding whether to use socket.io or go with plain http. In the app the node.js server will be basically an api server which serves json to the javascript client or may be mobile clients too. The web app will also has chat messeneger for its users, this is where socket.io comes in.
I am not sure whether to use socket.io for the whole app or only for the chat part. Although my app itself could benefit from socket.io but its nothing that I think can't be done using plain http and client making more requests to the server.
I have read at several places that sometimes socket.io can be difficult to scale for more users.
Socket.io often crashes and specially creates probs when there are firewall in clients system.
More importantly.....I checked out socket.io user list and did not find many users, so was curious to know what kind of platform is more know chat network like facebook messenger, google talk etc are built upon, Are any built using http-ajax and continues querying to the server.
Please help me out in solving this question. Some might argue that this is a opinion based question. But what actually I am trying to figure out the implementation of socket.io and its limitation.
I would suggest serving your API over HTTP and leave the real-time business to Socket.io. If you are adverse to using Websockets, like #GeoPheonix stated, you can choose from a variety of transport methods using both socket.io and sockjs (https://github.com/sockjs/sockjs-node).
As far as scaling is concerned, I deployed a socket.io based real-time analytics/tracking service for a very large application with ana average of 400+ concurrent connections with no visible performance impact, but this may depend on the implementation and hardware.
Socket.io is faster than plain http. I recommend you to use it for all since you have to have a chat in first place.
In my case, real-time Texas Hold'em-like game can receive up to 2500 concurrent with one node process. However, if you change transport from websocket to xhr-polling, It can receive like more 10x than pure websocket. Your application is just chat so, I guess a little slow down wouldn't be a problem. If you sure you will exceed this number, yes, scale socket.io is a pain.
This problem will happen only if you open socket.io for port other than 80 and 443. If you have frontend web server with other language already, you can still use socket.io on another subdomain to be able to run on port 80 without conflict with your main frontend web server. Socket.io support cross-domain without a problem.
Have you used trello.com? If not, try it :). It's best for task management or even some Agile thing. They used socket.io. https://c9.io/ is another one. It's online IDE with google doc-like collaborative. One thing to note is xhr-polling trasport in socket.io is the same with http-ajax with long-polling (Better than general ajax). You can read more info at:
http://book.mixu.net/node/ch13.html

Realtime application - alternative for socket.io (node.js)

I use node.js.
I am looking for an alternative for socket.io.
I need to send a private message to the user.
What is the alternative for the SOCKET.IO?
You haven't really explained why you're looking for Socket.IO. If you provide more details into why Socket.IO isn't working for you then you can get a better answer. Otherwise I'll just point you to a duplicate of this question.
Node.JS Looking for an alternative to socket.IO

adding web socket chat into existing nodejs app

I've made nodejs application by this template. And now I want to add simple websocket chat.
My question is: do I have to completely rewrite that application to add websocket chat or I can to save that structure?
You can create a chat using Socket.IO (or another library), it's perfectly possible (and probably a best practice even) to separate the two: the regular server and the WebSocket server.
The two aren't tied together.
I have never used the express MVC template, but socket.io does not use express routes and from my experience they exist side by side just fine. Just add your socket.io server code to app.js to test it out and you can use the client side code within any of your express views.
This assumes you're using socket.io of course. I have no experience with other methods of using websockets with node.js.

Resources