Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run websocket at /? #7

Open
and7ey opened this issue Jun 8, 2020 · 9 comments
Open

How to run websocket at /? #7

and7ey opened this issue Jun 8, 2020 · 9 comments
Labels
bug Something isn't working

Comments

@and7ey
Copy link

and7ey commented Jun 8, 2020

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
Copy link
Author

and7ey commented Jun 9, 2020

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.

@ErikPDev
Copy link

ErikPDev commented Jun 9, 2020

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

@and7ey
Copy link
Author

and7ey commented Jun 10, 2020

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

@Sandertv
Copy link
Owner

I'm looking into a fix right now.

@Sandertv
Copy link
Owner

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 Sandertv added the bug Something isn't working label Jun 11, 2020
@and7ey
Copy link
Author

and7ey commented Jun 11, 2020

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

@and7ey
Copy link
Author

and7ey commented Jun 12, 2020

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.

@ErikPDev
Copy link

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

@and7ey
Copy link
Author

and7ey commented Sep 19, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants