本文整理匯總了Golang中github.com/pipeviz/pipeviz/Godeps/_workspace/src/github.com/gorilla/websocket.Conn.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.Close方法的具體用法?Golang Conn.Close怎麽用?Golang Conn.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pipeviz/pipeviz/Godeps/_workspace/src/github.com/gorilla/websocket.Conn
的用法示例。
在下文中一共展示了Conn.Close方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
}
}
示例2: 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
}
}
}
示例3: 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
}
}
}
示例4: 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
}
}
}
}