Categorygithub.com/asmyasnikov/go-multicast
modulepackage
1.0.1
Repository: https://github.com/asmyasnikov/go-multicast.git
Documentation: pkg.go.dev

# README

go-multicast

PkgGoDev GoDoc Go Report Card codecov tests lint

package provide multicast sending messages to all connected clients

Usage:

package main

import (
	"context"
	"github.com/asmyasnikov/go-multicast"
	"github.com/asmyasnikov/go-multicast/helpers/websocket"
	"net/http"
	"fmt"
	"time"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	m := multicast.New(
		ctx,
		func(err error) {
			fmt.Println(err)
		},
		nil, // latest message replace snapshot
		time.Second,
	)
	go func() {
		for {
			m.SendAll(time.Now())
			time.Sleep(time.Millisecond * 100)
		}
	}()
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		conn, err := websocket.Upgrader.Upgrade(w, r, nil)
		if err != nil {
			fmt.Println(err)
			return
		}
		websocket.Add(
			m,
			conn,
			nil,
		)
	})
	if err := http.ListenAndServe(":80", nil); err != nil {
		fmt.Println(err)
	}
}

# Packages

No description provided by the author

# Functions

New creates new Multicast with empty clients.

# Structs

ChangeIntervalMessage is a specified message for change interval of sending high-frequency messages.
Multicast is a main communicator for linking sender and receivers.