Skip to content

[question]How can i get error message when message beyond MaxMessageSize config #1911

@Eminlin

Description

@Eminlin

Thanks for your great project!!!

There has some problem when i use iris 11.1.1, i was setting MaxMessageSize when websocket.New, i try to send a data larger than this size, the websocket channel will be disconnected by itself , but no error information can be get.

I can't find any information, and I can't see the method from the source code. After testing several methods, there is no effect, so I have to ask questions here.

Hope to get some advice, sorry for my pool english......

There are some code method which i try

func main() {
	app := iris.Default()
        mvc.Configure(app.Party("/ws"), websocket.ConfigureWS)
        .....
}
func ConfigureWS(m *mvc.Application) {
	ws := websocket.New(websocket.Config{MaxMessageSize: 3145728, ReadTimeout: time.Minute,
		Error: func(w http.ResponseWriter, r *http.Request, status int, reason error) {
			util.GetLog().Error("websocket new err", status, reason.Error())
		}})
       ws.OnConnection(func(c websocket.Connection) {
		fmt.Println(c.Context())
		fmt.Println(c)
		fmt.Println(ws.GetConnections())
		c.OnDisconnect(func() {
			fmt.Println(c)
		})
		c.OnError(func(e error) {
			fmt.Println(e.Error())
		})
	})
       m.Register(
		ws.Upgrade, ws,
	)
	websocketController := new(WebsocketListen)
	m.Handle(websocketController)
}

type WebsocketListen struct {
	Ctx                   iris.Context
	Conn                  websocket.Connection
	WS                    *websocket.Server
}
func (c *WebsocketListen) Get() {
       c.WS.OnConnection(func(c websocket.Connection) {
		fmt.Println(c.Err())
	})

	c.Conn.OnError(func(e error) {
		fmt.Println(e)
	})
	//fmt.Println(c.Conn.ID())
	c.Conn.OnLeave(c.onLeave)
	c.Conn.OnMessage(c.OnMessage)

	c.Conn.OnError(func(err error) {
		fmt.Println(err.Error())
	})

	c.Conn.OnDisconnect(func() {
		fmt.Println(c.Conn.Err())
	})

	c.Conn.Wait()
}

func (c *WebsocketListen) onLeave(roomName string) {
	fmt.Println(c.Ctx.Request().Context().Err())
        util.GetWsLog().Debug("Leave channelId", c.Conn.ID())
}

Thanks again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions