1 Star 2 Fork 0

api-go / iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 989 Bytes
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"github.com/kataras/iris"
"github.com/googollee/go-socket.io"
)
/*
go get -u github.com/googollee/go-socket.io
*/
func main() {
app := iris.New()
server, err := socketio.NewServer(nil)
if err != nil {
app.Logger().Fatal(err)
}
server.On("connection", func(so socketio.Socket) {
app.Logger().Infof("on connection")
so.Join("chat")
so.On("chat message", func(msg string) {
app.Logger().Infof("emit: %v", so.Emit("chat message", msg))
so.BroadcastTo("chat", "chat message", msg)
})
so.On("disconnection", func() {
app.Logger().Infof("on disconnect")
})
})
server.On("error", func(so socketio.Socket, err error) {
app.Logger().Errorf("error: %v", err)
})
// serve the socket.io endpoint.
app.Any("/socket.io/{p:path}", iris.FromStd(server))
// serve the index.html and the javascript libraries at
// http://localhost:8080
app.StaticWeb("/", "./public")
app.Run(iris.Addr("localhost:8080"), iris.WithoutPathCorrection)
}
1
https://gitee.com/netscript/iris.git
git@gitee.com:netscript/iris.git
netscript
iris
iris
v11.1.1

搜索帮助