Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sockjs

Package Overview
Dependencies
Maintainers
5
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sockjs

SockJS-node is a server counterpart of SockJS-client a JavaScript library that provides a WebSocket-like object in the browser. SockJS gives you a coherent, cross-browser, Javascript API which creates a low latency, full duplex, cross-domain communication

  • 0.3.24
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12M
increased by0.46%
Maintainers
5
Weekly downloads
 
Created

What is sockjs?

SockJS is a JavaScript library that provides a WebSocket-like object in environments where true WebSockets are not available or not fully supported. It is designed to work both on the client-side and server-side to enable seamless communication between the two. SockJS provides a consistent API and attempts to provide a low-latency, full duplex, cross-domain communication channel that can work even behind restrictive corporate proxies.

What are sockjs's main functionalities?

Server-side WebSocket emulation

This code sample demonstrates how to create a SockJS server that emulates a WebSocket. It listens for connections on the '/echo' path and simply echoes back any messages it receives.

const http = require('http');
const sockjs = require('sockjs');
const echo = sockjs.createServer({ prefix: '/echo' });
echo.on('connection', function(conn) {
  conn.on('data', function(message) {
    conn.write(message);
  });
});
const server = http.createServer();
echo.installHandlers(server, { prefix: '/echo' });
server.listen(9999, '0.0.0.0');

Client-side WebSocket emulation

This code sample shows how to create a SockJS client that connects to a SockJS server. It sends a message when the connection is opened and logs any messages it receives before closing the connection.

const SockJS = require('sockjs-client');
let sock = new SockJS('http://localhost:9999/echo');
sock.onopen = function() {
  console.log('open');
  sock.send('test');
};
sock.onmessage = function(e) {
  console.log('message', e.data);
  sock.close();
};
sock.onclose = function() {
  console.log('close');
};

Other packages similar to sockjs

Keywords

FAQs

Package last updated on 03 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc