Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate SockJS with another web framework

As an alternative to Socket.io, there is SockJS (https://github.com/sockjs/sockjs-client), which seems to be better maintained and more stable than Socket.io.

This question is about the conceptual understanding the architecture of using SockJS with a web framework, say, for building a chat application

My current understanding is that you need the SockJS-client and a SocketJS server (in my case, I intend to use SockJS-Tornado (https://github.com/MrJoes/sockjs-tornado)) to be able to make websockets-style communication.

But how does SockJS (SockJS-client + SockJS-Tornado) tie together with a web framework that does the rest of the work (e.g. serving the page, writing/reading to/from db, etc). For instance, how would SockJS-Tornado component communicates with the web server of the framework? In particular, any direction of doing this with web2py (a python web framework) is highly appreciated.

like image 514
MLister Avatar asked May 03 '12 17:05

MLister


People also ask

Is SockJS WebSocket?

SockJS is a browser JavaScript library that provides a WebSocket-like object. SockJS gives you a coherent, cross-browser, Javascript API which creates a low latency, full duplex, cross-domain communication channel between the browser and the web server. Under the hood SockJS tries to use native WebSockets first.

Is Stomp deprecated?

This project is no longer maintained. If you encounter bugs with it or need enhancements, you can fork it and modify it as the project is under the Apache License 2.0.

What is the difference between WebSocket and socket IO?

Key Differences between WebSocket and socket.ioIt provides the Connection over TCP, while Socket.io is a library to abstract the WebSocket connections. WebSocket doesn't have fallback options, while Socket.io supports fallback. WebSocket is the technology, while Socket.io is a library for WebSockets.

What is Stomp in WebSocket?

STOMP, an acronym for Simple Text Oriented Messaging Protocol, is a simple HTTP-like protocol for interacting with any STOMP message broker. Any STOMP client can interact with the message broker and be interoperable among languages and platforms.


1 Answers

You're right, for SockJS you need a sockjs-capable server and a in-browser javascript client library.

There are generally two integration patterns, let's say you want to use sockjs-tornado:

  1. You may have all your site served from Tornado. With that, hook sockjs-tornado to some path, for example 'http://mysite.com/sockjs'. In this scenario both your website and sockjs will be served from mysite.com domain.
  2. You may keep your site in whatever language/framework it's written and add sockjs-serveras another compontent, under a different domain, like. 'http://sockjs.mysite.com/sockjs'.

Additionally, you may use any variation of this - for example: have two servers internally but expose them as one domain by using a smart loadblancer (like haproxy).

like image 126
Marek Avatar answered Oct 01 '22 00:10

Marek