Integration of Beego and Websocker

Source: Internet
Author: User

The problem happened just last week.

The weekend at home according to the online program test.

Hope to go well next week ~ ~

Url:

http://blog.csdn.net/u012210379/article/details/72912056

Package Controllersimport ("Beegows/models" "FMT" "Log" "Time" "Github.com/astaxie/beego"//"Github.com/astaxie/beego /toolbox "" Github.com/gorilla/websocket ") type Mywebsocketcontroller struct {beego. Controller}var upgrader = WebSocket. Upgrader{}func (c *mywebsocketcontroller) Get () {ws, Err: = Upgrader. Upgrade (C.ctx.responsewriter, c.ctx.request, nil) if err! = Nil {log. Fatal (Err)}//defer ws. Close () Clients[ws] = true/*for {time. Sleep (time. Second * 3) Msg: = models. Message{message: "This is the data sent to the page" + Time. Now (). Format ("2006-01-02 15:04:05")}broadcast <-msg}*/for {time. Sleep (time. Second * 3) var msg models. Message//Read in a new message as JSON and map it to a message objecterr: = ws. Readjson (&msg) if err! = Nil {log. Printf ("The page may be disconnected from WS.") Readjson error:%v ", err) Delete (clients, WS) break} else {fmt. PRINTLN ("Receive information back from page feedback", MSG. Message)}broadcast <-msg}}

  

Integration of Beego and Websocker

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.