melody websocket 使用
2017-10-07 17:15
211 查看
melody: go 语言极简websocket 框架。比标准库简单好用点。可以指定拦截器。
github地址:https://github.com/olahol/melody
GitHub地址中 echo (https://github.com/olahol/melody/tree/master/examples/chat-echo)例子有点问题故修改如下:
main.go:
github地址:https://github.com/olahol/melody
GitHub地址中 echo (https://github.com/olahol/melody/tree/master/examples/chat-echo)例子有点问题故修改如下:
main.go:
import ( "github.com/labstack/echo" "github.com/labstack/echo/middleware" "gopkg.in/olahol/melody.v1" "net/http" ) func main() { e := echo.New() m := melody.New() e.Use(middleware.Logger()) e.Use(middleware.Recover()) e.GET("/", func(c echo.Context) error { http.ServeFile(c.Response().Writer, c.Request(), "index.html") return nil }) e.GET("/ws", func(c echo.Context) error { m.HandleRequest(c.Response().Writer, c.Request()) return nil }) m.HandleMessage(func(s *melody.Session, msg []byte) { m.BroadcastFilter(msg, func(q *melody.Session) bool { return true }) }) e.Start(":5000") }
相关文章推荐
- 使用 HTML5 WebSocket 构建实时 Web 应用
- WebSocket简单使用(三) - 服务器端
- 【spring+websocket的使用】
- 使用Node.js+Socket.IO搭建WebSocket实时应用
- Android使用Websocket实现聊天室
- websocket使用demo
- vue使用websocket
- websocket java使用demo。包含客户端与服务端使用
- 使用angularjs异步请求数据(http请求或者使用Websocket)的时候,更新$scope中的dom的方法
- 使用Node.js+Socket.IO搭建WebSocket实时应用
- IOS学习之websocket使用方法
- 使用websocket的组件socket.io实现最简单的聊天室功能。
- 使用 HTML5 WebSocket 构建实时 Web 应用
- 使用nginx作为websocket的proxy server
- 使用cocoscreator + node.js + websocket实现简单的聊天服务
- Java web项目使用webSocket
- 使用WebSocket实现即使通讯(实现一个群聊的聊天室)
- Unity使用WebSocket(基于BaseHTTP插件)
- 使用webSocket实现及时通信
- 使用Websocket实现消息推送(下)