本文整理汇总了Golang中github.com/pipeviz/pipeviz/Godeps/_workspace/src/github.com/gorilla/websocket.Conn类的典型用法代码示例。如果您正苦于以下问题:Golang Conn类的具体用法?Golang Conn怎么用?Golang Conn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Conn类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: graphToSock
func graphToSock(ws *websocket.Conn, g system.CoreGraph) {
j, err := graphToJSON(g)
if err != nil {
logrus.WithFields(logrus.Fields{
"system": "webapp",
"err": err,
}).Error("Error while marshaling graph into JSON for transmission over websocket")
}
if j != nil {
ws.SetWriteDeadline(time.Now().Add(writeWait))
if err := ws.WriteMessage(websocket.TextMessage, j); err != nil {
logrus.WithFields(logrus.Fields{
"system": "webapp",
"err": err,
}).Error("Error while writing graph data to websocket")
return
}
}
}
开发者ID:sdboyer,项目名称:pipeviz,代码行数:20,代码来源:websocket.go
示例2: wsWriter
func wsWriter(ws *websocket.Conn) {
graphIn := broker.Get().Subscribe()
pingTicker := time.NewTicker(pingPeriod)
defer func() {
pingTicker.Stop()
broker.Get().Unsubscribe(graphIn)
ws.Close()
}()
// write the current graph state first, before entering loop
graphToSock(ws, latestGraph)
var g system.CoreGraph
for {
select {
case <-pingTicker.C:
// ensure client connection is healthy
ws.SetWriteDeadline(time.Now().Add(writeWait))
if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
return
}
case g = <-graphIn:
graphToSock(ws, g)
}
}
}
开发者ID:sdboyer,项目名称:pipeviz,代码行数:25,代码来源:websocket.go
示例3: writer
func writer(ws *websocket.Conn, lastMod time.Time) {
lastError := ""
pingTicker := time.NewTicker(pingPeriod)
fileTicker := time.NewTicker(filePeriod)
defer func() {
pingTicker.Stop()
fileTicker.Stop()
ws.Close()
}()
for {
select {
case <-fileTicker.C:
var p []byte
var err error
p, lastMod, err = readFileIfModified(lastMod)
if err != nil {
if s := err.Error(); s != lastError {
lastError = s
p = []byte(lastError)
}
} else {
lastError = ""
}
if p != nil {
ws.SetWriteDeadline(time.Now().Add(writeWait))
if err := ws.WriteMessage(websocket.TextMessage, p); err != nil {
return
}
}
case <-pingTicker.C:
ws.SetWriteDeadline(time.Now().Add(writeWait))
if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
return
}
}
}
}
开发者ID:sdboyer,项目名称:pipeviz,代码行数:40,代码来源:main.go
示例4: wsReader
func wsReader(ws *websocket.Conn) {
defer ws.Close()
ws.SetReadLimit(512)
ws.SetReadDeadline(time.Now().Add(pongWait))
ws.SetPongHandler(func(string) error { ws.SetReadDeadline(time.Now().Add(pongWait)); return nil })
// for now, we ignore all messages from the frontend
for {
_, _, err := ws.ReadMessage()
if err != nil {
break
}
}
}
开发者ID:sdboyer,项目名称:pipeviz,代码行数:13,代码来源:websocket.go
示例5: reader
func reader(ws *websocket.Conn) {
defer ws.Close()
ws.SetReadLimit(512)
ws.SetReadDeadline(time.Now().Add(pongWait))
ws.SetPongHandler(func(string) error { ws.SetReadDeadline(time.Now().Add(pongWait)); return nil })
for {
_, _, err := ws.ReadMessage()
if err != nil {
break
}
}
}
开发者ID:sdboyer,项目名称:pipeviz,代码行数:12,代码来源:main.go
注:本文中的github.com/pipeviz/pipeviz/Godeps/_workspace/src/github.com/gorilla/websocket.Conn类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论