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

Is mux supposed to work with WebSocket? #29

Closed
tchap opened this issue Jul 4, 2013 · 10 comments
Closed

Is mux supposed to work with WebSocket? #29

tchap opened this issue Jul 4, 2013 · 10 comments

Comments

@tchap
Copy link

tchap commented Jul 4, 2013

Hi,

I am using mux together with WebSocket in my app and I am constantly getting 404. When I replace mux with http.ServeMux, everything starts working. I register the handler with

r.Handle("/ws", ws.Handler(s.handleWSConnection))

and

mx := http.NewServeMux()
mx.Handle("/", r)
mx.Handle("/ws", ws.Handler(s.handleWSConnection))

is the working code.

I am asking because I saw people using it on the internet, so I don't know if it broke recently or so...

Thanks for the reply!

Regards,
Ondra Kupka

@kisielk
Copy link
Contributor

kisielk commented Jul 8, 2013

I don't see any obvious reasons why it should not work. Can you provide any more details? Are you sure the client is going specifically to the /ws URL and not a sub-path thereof? The gorilla mux example will return 404 for anything that's not exactly /ws or /

@tchap
Copy link
Author

tchap commented Jul 8, 2013

Even

r.PathPrefix("/ws").Handler(ws.Server{
        Handshake: s.handleWSHandshake,
        Handler:   s.handleWSConnection,
})

is not working. It's giving me GET /ws -> 404.

@kisielk
Copy link
Contributor

kisielk commented Jul 8, 2013

Do you have the actual code available somewhere, to provide a runnable example?

@longsleep
Copy link

Gorilla works fine with /ws handler for us. See https://github.com/strukturag/spreed-speakfreely/blob/master/src/app/spreed-speakfreely-server/main.go#L309 - i guess this can be closed.

@kisielk
Copy link
Contributor

kisielk commented Apr 7, 2014

Yeah, I've seen other people using it successfully. Please reopen if there is a specific example of it not working.

@kisielk kisielk closed this as completed Apr 7, 2014
@bipin244
Copy link

Can anyone please share a working example of WebSocket with gorilla mux?

@elithrar
Copy link
Contributor

elithrar commented Jul 25, 2018 via email

@elithrar
Copy link
Contributor

elithrar commented Jul 25, 2018 via email

@bipin244
Copy link

Okay thank my friend.

@jeniasaigak
Copy link

Just had the same issue. In my case, it was not related to the library. I just missed the fact that I had another route before this one which took the request:

r.HandleFunc("/some/path/{id}", a.route) // takes the /**/ws request instead of the needed handler
r.HandleFunc("/some/path/ws", a.wsRoute)

Changing lines order solved the issue for me 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants