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 can I use websocket #51

Closed
PEKTOP opened this issue Jul 7, 2014 · 8 comments
Closed

How can I use websocket #51

PEKTOP opened this issue Jul 7, 2014 · 8 comments
Assignees
Labels

Comments

@PEKTOP
Copy link

PEKTOP commented Jul 7, 2014

Hello! Thank you for cool framework!

I use code.google.com/p/go.net/websocket package

http.Handle("/socket", websocket.Handler(echoHandler))

How can I handle websocket with gin?

@manucorporat
Copy link
Contributor

Please, try this:

r := gin.New()
r.GET("/ws", func(c *gin.Context) {
    handler := websocket.Handler(EchoServer)
    handler.ServeHTTP(c.Writer, c.Req)
})
r.Run(":8080")

@PEKTOP
Copy link
Author

PEKTOP commented Jul 8, 2014

@manucorporat, thanks!

@PEKTOP PEKTOP closed this as completed Jul 8, 2014
@PEKTOP
Copy link
Author

PEKTOP commented Jul 9, 2014

@manucorporat , after last update i try:

r := gin.New()
r.GET("/ws", func(c *gin.Context) {
    handler := websocket.Handler(EchoServer)
    handler.ServeHTTP(c.Writer, c.Req)
})
r.Run(":8080")

Log:

PANIC: interface conversion: *gin.responseWriter is not http.Hijacker: missing method Hijack

@PEKTOP PEKTOP reopened this Jul 9, 2014
@zmarcantel
Copy link

I have added the .Hijack() method and an example in my working fork as part of #16, but due to some differences in practice my fork has become incompatible.

I don't want to double the work/headache for myself or the repo maintainer so I won't be making another fork to submit another pull request over a renamed function or two.

If you wanna dig in, look here:
https://github.com/zmarcantel/gin

The relevant parts are in:
response_writer.go
examples/websockets/example_websocket.go

@olebedev
Copy link

#105

@manucorporat
Copy link
Contributor

Issue fixed! merged in develop:
4a24c47
7a87c5c
8f1bbc6

@sjbog
Copy link

sjbog commented Aug 31, 2014

@manucorporat, push to master, so that "go get" would work

@manucorporat
Copy link
Contributor

Already merged in master ;)

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

No branches or pull requests

6 participants