Skip to content

marcus2vinicius/socketio-pub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Websocket - Pub/Sub

Socket.io nodejs for Publish/Subscribe

Available on :

Running

Local

npm install
node server.js

docker

$ docker-compose up

Open localhost:3000

Usage

Client Receiving msgs

    import { io } from "https://cdn.socket.io/4.4.1/socket.io.esm.min.js";
    const socket = io("https://vinymd-socketio-pub.onrender.com");

    socket.on("connect", () => {
        console.log("Connected Socket.io");
        start()
    });

    socket.on("disconnect", () => {
        console.log("Disconnect Socket.io");
    });

    function start(){
        socket.emit("subscribe", 'topic1');

        socket.on('topic1', (msg) => {
           console.log(`Message received from topic1: ${msg}`);
        })
    }

Client Sending msgs

   socket.emit("broadcast", {channel: 'topic1', message: 'Message sent from html2'});

About

Socket.io nodejs for Publish/Subscribe

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published