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

faye-websocket

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faye-websocket

Standards-compliant WebSocket server and client

  • 0.11.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14M
decreased by-2.91%
Maintainers
1
Weekly downloads
 
Created

What is faye-websocket?

The faye-websocket npm package is a WebSocket client and server implementation that allows you to build real-time web applications. It provides an easy-to-use API for handling WebSocket connections and messages.

What are faye-websocket's main functionalities?

WebSocket Client

This code sample demonstrates how to create a WebSocket client that connects to a server, sends a message, and listens for messages and the close event.

const WebSocket = require('faye-websocket');
const ws = new WebSocket.Client('ws://www.example.com/');

ws.on('open', function(event) {
  console.log('Connection established');
  ws.send('Hello, world!');
});

ws.on('message', function(event) {
  console.log('Received message: ' + event.data);
});

ws.on('close', function(event) {
  console.log('Connection closed', event.code, event.reason);
  ws = null;
});

WebSocket Server

This code sample shows how to set up a WebSocket server that can accept connections, echo received messages back to the client, and handle the close event.

const http = require('http');
const WebSocket = require('faye-websocket');

const server = http.createServer();

server.on('upgrade', function(request, socket, body) {
  if (WebSocket.isWebSocket(request)) {
    const ws = new WebSocket(request, socket, body);

    ws.on('message', function(event) {
      ws.send(event.data);
    });

    ws.on('close', function(event) {
      console.log('Connection closed', event.code, event.reason);
      ws = null;
    });
  }
});

server.listen(3000);

Other packages similar to faye-websocket

Keywords

FAQs

Package last updated on 24 May 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