Skip to content

Use with go-gin #34

Answered by zishang520
robertchar92 asked this question in Q&A
Dec 12, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

This is a short demo:

package main

import (
	"regexp"

	"github.com/gin-gonic/gin"
	_types "github.com/zishang520/engine.io-go-parser/types"
	"github.com/zishang520/engine.io/v2/utils"
	"github.com/zishang520/socket.io/v2/socket"
)

func main() {
	r := gin.Default()
	socketio := socket.NewServer(nil, nil)
	socketio.Of(
		regexp.MustCompile(`/\w+`),
		nil,
	).Use(func(client *socket.Socket, next func(*socket.ExtendedError)) {
		utils.Log().Success("MId:%v", client.Connected())
		next(nil)
	}).On("connection", func(clients ...interface{}) {
		client := clients[0].(*socket.Socket)
		// utils.Log().Success("/ test Handshake:%v", client.Handshake())
		client.Broadcast().Emit("hi test")
		client.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@robertchar92
Comment options

Answer selected by robertchar92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants