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

simple-websocket

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-websocket

Simple, EventEmitter API for WebSockets (browser)

  • 7.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
394K
increased by3.36%
Maintainers
1
Weekly downloads
 
Created

What is simple-websocket?

The simple-websocket npm package provides a straightforward API for creating WebSocket clients and servers. It is designed to be easy to use and lightweight, making it suitable for simple WebSocket communication tasks.

What are simple-websocket's main functionalities?

Creating a WebSocket Client

This code demonstrates how to create a WebSocket client using the simple-websocket package. It connects to a WebSocket server, sends a message upon connection, and listens for incoming messages and connection closure.

const SimpleWebSocket = require('simple-websocket');
const ws = new SimpleWebSocket('ws://example.com');

ws.on('connect', () => {
  console.log('Connected to server');
  ws.send('Hello, server!');
});

ws.on('data', (data) => {
  console.log('Received message:', data);
});

ws.on('close', () => {
  console.log('Connection closed');
});

Creating a WebSocket Server

This code demonstrates how to create a WebSocket server using the simple-websocket package. The server listens for new client connections, sends a welcome message to each client, and handles incoming messages and disconnections.

const SimpleWebSocketServer = require('simple-websocket/server');
const server = new SimpleWebSocketServer({ port: 3000 });

server.on('connection', (socket) => {
  console.log('New client connected');
  socket.send('Welcome, client!');

  socket.on('data', (data) => {
    console.log('Received message from client:', data);
  });

  socket.on('close', () => {
    console.log('Client disconnected');
  });
});

Other packages similar to simple-websocket

Keywords

FAQs

Package last updated on 27 Jul 2018

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