New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

http-websocket-server

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-websocket-server

Simple http-server with websocket bindings

latest
Source
npmnpm
Version
0.2.1
Version published
Weekly downloads
2
-71.43%
Maintainers
1
Weekly downloads
 
Created
Source

http-websocket-server

A simple command line http-server with websocket routing. Built with socket.io as websocket framework with an added layer for simplified client communication.

Quickly build sites with client communication without writing any server code.

Install

Install globally with npm:

npm install -g http-websocket-server

Usage

Start server

Start a server with:

http-websocket-server [server-root] [--port=port]

Client

Connect to an application from the client by specifying the applications id.

// socket.io library is served by default from the server
<script src="/socket.io/socket.io.js"></script>
<script>
  var appId = 'myApp';
  var socket = io();
  var myConnectionId;
  
  socket.on('connect', function() {
    // This is my id which other clients can reference
    myConnectionId = socket.io.engine.id;
  
    // Connect to the appId you wish to use
    socket.emit('app.connect', {
      appId: appId
    });
  });
  
  socket.on('app.connect', function() {
    console.log('Connected to app: ' + appId);
  });
</script>

Broadcasting messages to other clients in the same server-app.

socket.on('app.connect', function() {
  socket.emit('app.emit', {
    event: 'hello', // Event name that other clients listen to
    data: {
      name: 'My name'
    }
  });
});

// Listen to "hello" message from other clients
socket.on('hello', function(data) {
  console.log(data.name + ' says hello');
});

Sending messages to a specific client

socket.on('app.connect', function() {
  socket.emit('app.connections');
});

socket.on('app.connections', function(data) {
  var firstClient = data.connections[0];
  if (firstClient) {
    socket.emit('app.emit', {
      event: 'special hello',
      to: firstClient.id,
      data: {
        message: 'A special hello to you from me'
      }
    });
  }
});

socket.on('special.hello', function(data) {
  console.log('A special message received: ' + data.message);
});

Keywords

http

FAQs

Package last updated on 07 Aug 2015

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