Gin: How can I use websocket

Created on 7 Jul 2014  路  8Comments  路  Source: gin-gonic/gin

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?

bug

Most helpful comment

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")

All 8 comments

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")

@manucorporat, thanks!

@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

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

105

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

Already merged in master ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iiinsomnia picture iiinsomnia  路  3Comments

Bloomca picture Bloomca  路  3Comments

nxvl picture nxvl  路  3Comments

mastrolinux picture mastrolinux  路  3Comments

boneq picture boneq  路  3Comments