kataras / iris

The fastest HTTP/2 Go Web Framework. New, modern and easy to learn. Fast development with Code you control. Unbeatable cost-performance ratio :rocket:
https://www.iris-go.com
BSD 3-Clause "New" or "Revised" License
25.15k stars 2.48k forks source link

How to use custom websockets[BUG] #2412

Open juxiaoming opened 5 months ago

juxiaoming commented 5 months ago
app := iris.New()
appRouter := app.Party("/api")
appRouter.PartyFunc("/record", func(request router.Party) {
        request.Any("/ws", hero.Handler(newRecordHandler.Ws))
})
var upgrader = websocket.Upgrader{
    ReadBufferSize:  10240,
    WriteBufferSize: 10240,
    CheckOrigin: func(r *http.Request) bool {
        return true
    },
}
func (r *RecordHandler) Ws(ctx iris.Context) {
  conn, _:= upgrader.Upgrade(ctx.ResponseWriter(), ctx.Request(), nil)

go func(){
   err := conn.WriteMessage(websocket.TextMessage,[]byte("ok"))
  //[HTTP Server] http: response.Write on hijacked connection from github.com/kataras/iris/v12/context.(*responseWriter).Write (response_writer.go:276)???
}()
for {
       _, message, err := conn.ReadMessage()
      //close 1006 (abnormal closure): unexpected EOF ????
 }
}

How can I make it work properly