Websocket server, implemented flow Room style

Related tags

Websockets ignite
Overview

ignite

A websocket server module. Require redis to scale to multi nodes.

Client/server message follow format

type Message struct {
	Event   string          `json:"event"`
	Payload json.RawMessage `json:"payload"`
}

use module like the code below.

package main

import (
	"encoding/json"
	"fmt"
	"os"

	"github.com/dongnguyenltqb/ignite"
)

func main() {
	forever := make(chan bool)

	hub := ignite.NewServer(os.Getenv("addr"), "/ws", "localhost:6379", "", 10)
	fmt.Println("Websocket is listen on", os.Getenv("addr"))
	hub.OnNewClient = func(client *ignite.Client) {
		// Send indentity message
		client.SendIdentityMsg()
		// Join a room
		client.Join("room-number-1")
		// Send to a room except some client
		client.SendMsgToRoomWithExcludeClient("room-number-1", []string{client.Id}, ignite.Message{
			Event: "new_client_enter_room",
		})
		// Register handle for an event
		client.On("buy", "1", func(payload json.RawMessage) {
			client.SendMsg(ignite.Message{
				Event:   "test",
				Payload: payload,
			})
			helloMsgPayload, _ := json.Marshal("Hello world")
			// Send to all member in a room
			client.SendMsgToRoom("room-number-1", ignite.Message{
				Event:   "test_room_1",
				Payload: helloMsgPayload,
			})
		})
		client.OnClose(func(reason string) {
			fmt.Println("Client ", client.Id, " closed: ", reason)
		})
	}
	<-forever
}

send/received message

{"event":"buy","payload":"PTB"} < {"event":"bought","payload":"PTB"} >">
➜  ignite git:(master) ✗ wscat -c "ws://localhost:8787/ws"
Connected (press CTRL+C to quit)
< {"event":"identity","payload":{"clientId":"48d44877-f04b-4e63-ad4b-ebf17899a4de"}}
> {"event":"buy","payload":"PTB"}
< {"event":"bought","payload":"PTB"}
>
You might also like...
WebSocket Command Line Client written in Go

ws-cli WebSocket Command Line Client written in Go Installation go get github.com/kseo/ws-cli Usage $ ws-cli -url ws://echo.websocket.org connected (

proxy your traffic through CDN using websocket

go-cdn2proxy proxy your traffic through CDN using websocket what does it do example server client thanks what does it do you can use this as a library

Chat bots (& more) for Zoom by figuring out their websocket protocol
Chat bots (& more) for Zoom by figuring out their websocket protocol

zoomer - Bot library for Zoom meetings Good bot support is part of what makes Discord so nice to use. Unfortunately, the official Zoom API is basicall

Tiny WebSocket library for Go.

RFC6455 WebSocket implementation in Go.

Simple example for using Turbos Streams in Go with the Gorilla WebSocket toolkit.

Go Example for TurboStreams over WebSockets Simple example for using Turbos Streams in Go with the Gorilla WebSocket toolkit.

Minimal and idiomatic WebSocket library for Go

websocket websocket is a minimal and idiomatic WebSocket library for Go. Install go get nhooyr.io/websocket Highlights Minimal and idiomatic API First

:notes: Minimalist websocket framework for Go
:notes: Minimalist websocket framework for Go

melody 🎶 Minimalist websocket framework for Go. Melody is websocket framework based on github.com/gorilla/websocket that abstracts away the tedious p

A modern, fast and scalable websocket framework with elegant API written in Go
A modern, fast and scalable websocket framework with elegant API written in Go

About neffos Neffos is a cross-platform real-time framework with expressive, elegant API written in Go. Neffos takes the pain out of development by ea

Terminal on browser via websocket

Terminal on browser via websocket. Supportted OS Linux Mac

Releases(v1.0.12)
Encrypted-websocket-chat - Encrypted websocket chat using golang

Encrypted websocket chat First version written in python This version should be

Artyom Artamonov 13 Sep 15, 2022
Websocket-chat - A simple websocket chat application

WebSocket Chat App This is a simple chat app based on websockets. It allows user

null 1 Jan 25, 2022
Turn any program that uses STDIN/STDOUT into a WebSocket server. Like inetd, but for WebSockets.

websocketd websocketd is a small command-line tool that will wrap an existing command-line interface program, and allow it to be accessed via a WebSoc

Joe Walnes 16.6k Dec 31, 2022
BrisGolang is a Go implementation of the game of briscola using the WebSocket protocol for client/server communication.

BrisGolang BrisGolang is a Go implementation of the game of briscola using the WebSocket protocol for client/server communication. Usage You can play

Calogero Miraglia 0 Nov 1, 2021
Just a PubSub Websocket Server

Eventual Agent Just a PubSub Websocket Server The eventual agent allows cluster local apps to subscribe and publish over network. Goals Provide a WebS

Joshua Tracey 2 Dec 24, 2022
HLive is a server-side WebSocket based dynamic template-less view layer for Go.

HLive HLive is a server-side WebSocket based dynamic template-less view layer for Go. HLive is a fantastic tool for creating complex and dynamic brows

Sam Hennessy 93 Jan 8, 2023
API that upgrades connection to use websocket. Contains server and client and testing how they communicate

Websocket Test API How to execute First run server using: make run-server. Then run many client instances with: make run-client. Then start typing in

null 0 Dec 25, 2021
Websocket server. Get data from provider API, clean data and send to websoket, when it's changed.

Описание Сервис получает данные по киберспортивным матчам CS:GO от провайдера, структурирует, очищает от лишнего и отправляет всем активным вебсокет к

null 1 Apr 6, 2022
A simple server to convert ATK-IMU901 serial data into websocket stream

A simple server to convert ATK-IMU901 serial data into WebSocket stream.

SuperMario SuperFans 1 Jan 31, 2022
A fast, well-tested and widely used WebSocket implementation for Go.

Gorilla WebSocket Gorilla WebSocket is a Go implementation of the WebSocket protocol. Documentation API Reference Chat example Command example Client

Gorilla Web Toolkit 18.6k Jan 2, 2023