From 7075ad8a28d9bf3fd0643d5b7fbea200226215fb Mon Sep 17 00:00:00 2001 From: redar Date: Sat, 14 Jun 2014 00:21:26 +0200 Subject: [PATCH] update chat example --- example/chat/controllers/ws.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/example/chat/controllers/ws.go b/example/chat/controllers/ws.go index 883bf323..862f89c9 100644 --- a/example/chat/controllers/ws.go +++ b/example/chat/controllers/ws.go @@ -60,9 +60,9 @@ func (c *connection) readPump() { break } switch op { - case websocket.OpPong: + case websocket.PongMessage: c.ws.SetReadDeadline(time.Now().Add(readWait)) - case websocket.OpText: + case websocket.TextMessage: message, err := ioutil.ReadAll(r) if err != nil { break @@ -89,14 +89,14 @@ func (c *connection) writePump() { select { case message, ok := <-c.send: if !ok { - c.write(websocket.OpClose, []byte{}) + c.write(websocket.CloseMessage, []byte{}) return } - if err := c.write(websocket.OpText, message); err != nil { + if err := c.write(websocket.TextMessage, message); err != nil { return } case <-ticker.C: - if err := c.write(websocket.OpPing, []byte{}); err != nil { + if err := c.write(websocket.PingMessage, []byte{}); err != nil { return } } @@ -149,8 +149,13 @@ type WSController struct { beego.Controller } +var upgrader = websocket.Upgrader{ + ReadBufferSize: 1024, + WriteBufferSize: 1024, +} + func (this *WSController) Get() { - ws, err := websocket.Upgrade(this.Ctx.ResponseWriter, this.Ctx.Request.Header, nil, 1024, 1024) + ws, err := upgrader.Upgrade(this.Ctx.ResponseWriter, this.Ctx.Request,nil) if _, ok := err.(websocket.HandshakeError); ok { http.Error(this.Ctx.ResponseWriter, "Not a websocket handshake", 400) return