How to run websocket at /?
and7ey opened this issue · comments
I am trying to replace default /ws
handler with /
or with the empty value. But it doesn't work.
With the code below the server is still available at /ws
.
server_config := &mcwss.Config {
HandlerPattern: "/",
Address: ":8000",
}
server := mcwss.NewServer(server_config)
But if I replace /
with /w
, then it works as expected.
Hi @ErikPDev, believe it should be something like -
player.OnBlockPlaced(func(event *event.BlockPlaced){
var msg = event.Message
})
See https://godoc.org/github.com/Sandertv/mcwss#Player.OnBlockPlaced
P.S. You should be creating a separate issue for your question.
Alright, thanks mate!
I'll create a separate issue next time.
Regards,
Erik.
@Sandertv, would appreciate your support..
Is there any way to run the server at /
?
I'm looking into a fix right now.
Seems like this is a Go specific thing... localhost:8000/anything works with /
as HandlerPattern, but for some reason without that anything
, it doesn't...
It is interesting since http.HandleFunc("/"...
works well.
Hmm, probably the following will help -
I tried to handle HTTP requests at \ws
in addition to WebSocket connections.
But I got the following error -
panic: http: multiple registrations for /ws
goroutine 1 [running]:
net/http.(*ServeMux).Handle(0xb49c80, 0x82929e, 0x3, 0x8b3bc0, 0xc000090d80)
/usr/lib/go-1.14/src/net/http/server.go:2403 +0x2b6
net/http.(*ServeMux).HandleFunc(...)
/usr/lib/go-1.14/src/net/http/server.go:2440
net/http.HandleFunc(...)
/usr/lib/go-1.14/src/net/http/server.go:2452
github.com/sandertv/mcwss.(*Server).Run(0xc0000c82c0, 0xc000090d70, 0x4)
/home/runner/go/pkg/mod/github.com/sandertv/mcwss@v1.1.1/server.go:61 +0x91
main.main()
/home/runner/wss/main.go:249 +0x281
Believe, it should work at the same time, since ports are different.
Probably this issue is dead, but did you try /*