mcwss icon indicating copy to clipboard operation
mcwss copied to clipboard

How to run websocket at /?

Open and7ey opened this issue 5 years ago • 9 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.

and7ey avatar Jun 08 '20 18:06 and7ey

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.

and7ey avatar Jun 09 '20 06:06 and7ey

Alright, thanks mate! I'll create a separate issue next time. Regards, Erik.

ErikPDev avatar Jun 09 '20 06:06 ErikPDev

@Sandertv, would appreciate your support.. Is there any way to run the server at /?

and7ey avatar Jun 10 '20 18:06 and7ey

I'm looking into a fix right now.

Sandertv avatar Jun 11 '20 13:06 Sandertv

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...

Sandertv avatar Jun 11 '20 15:06 Sandertv

It is interesting since http.HandleFunc("/"... works well.

and7ey avatar Jun 11 '20 16:06 and7ey

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/[email protected]/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.

and7ey avatar Jun 12 '20 21:06 and7ey

Probably this issue is dead, but did you try /*

ErikPDev avatar Sep 13 '20 19:09 ErikPDev

@ErikPDev, thanks. I tried to use '/*', but in result I can access the socket at localhost:8000/*, but localhost:8000 still doesn't work.

and7ey avatar Sep 19 '20 15:09 and7ey