zishang520/socket.io

socket.io client question

Closed this issue · 4 comments

from official documents, web side socket.io client can connect to special namespace, how to handle the connection event on server side ?

client side:

import { Socket, io } from "socket.io-client"

const socket = io("/admin")

server side:

skio := socket.NewServer( types.NewWebServer(nil), nil)

skio.On("/admin", func(clis ...any){})

not works.

when useing

skio := socket.NewServer( types.NewWebServer(nil), nil)

skio.On("connection", func(clis ...any){})

it does not catch the io("/admin") connection event

By default, skio listens to the root (/) event. You need to listen to the connection event after Of:

skio.Of("/admin", nil).On("connection", func(clis ...any){})

If you need dynamic namespace you can use regexp expression:

skio.Of(regexp.MustCompile(`/\w+`), nil).On("connection", func(clis ...any){})

thanks for your help. Another question is that I want to wrap (echo)[github.com/labstack/echo/v4] context when on connection, how can I do for this.