Giter Club home page Giter Club logo

socket-relay's Introduction

socket-relay

This is a simple socket server intended for frontend development work when the socket backend isn't implemented yet.

By default the server just broadcasts all events sent to it back to all other connected clients.

It supports dynamic namespaces, so you can use it for as many projects as you need.

Usage

Backend - Start server

Clone this repository and start the server with npm start. By default it runs on port 3000. For easy debugging it has decently gracious logging.

Frontend - Connect clients

It's supposed to be a drop-in replacement for development, so the front-end syntax stays the same. If you intend to keep the server running and use it for multiple projects you should set a namespace, so the events don't interfere with each other.

All socket.io configuration variables work as expected, so the server can run on a different URL than the client

// Connect to namespace
const socket = io("/test");

socket.on("connect", () => {
  // Send a test event with your own ID
  socket.send("test", socket.id);
  console.log("client connected", socket.id);
});

// Open another window and the first window should receive the ID of the 2nd one
socket.on("test", (msg) => {
  console.log("received", msg);
});

socket.on("disconnect", () => {
  console.log("client disconnected", socket.id);
});

socket-relay's People

Contributors

sensorydavide avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.