本文整理匯總了Golang中code/google/com/p/go/net/websocket.Conn.SetDeadline方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.SetDeadline方法的具體用法?Golang Conn.SetDeadline怎麽用?Golang Conn.SetDeadline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/google/com/p/go/net/websocket.Conn
的用法示例。
在下文中一共展示了Conn.SetDeadline方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleViewer
func handleViewer(conn *websocket.Conn) {
conn.SetReadDeadline(time.Now().Add(10 * time.Second))
var viewId string
if err := websocket.Message.Receive(conn, &viewId); err != nil {
return
}
slideId := index.getSlideId(viewId)
if slideId == "" {
return
}
listener := &slideListener{ch: make(chan int)}
registry.addListener(slideId, listener)
for {
slide := listener.get(1 * time.Minute)
if slide != 0 {
conn.SetDeadline(time.Now().Add(10 * time.Second))
if err := websocket.Message.Send(conn, fmt.Sprintf("%d", slide)); err != nil {
registry.removeListener(slideId, listener)
return
}
continue
}
if err := ping(conn); err != nil {
registry.removeListener(slideId, listener)
return
}
}
}
示例2: ping
func ping(conn *websocket.Conn) error {
conn.SetDeadline(time.Now().Add(10 * time.Second))
if err := websocket.Message.Send(conn, "ping"); err != nil {
return err
}
var pong string
if err := websocket.Message.Receive(conn, &pong); err != nil {
return err
}
return nil
}
示例3: handlePresenter
func handlePresenter(conn *websocket.Conn) {
conn.SetReadDeadline(time.Now().Add(10 * time.Second))
var slideIdParam string
if err := websocket.Message.Receive(conn, &slideIdParam); err != nil {
return
}
slideId, _ := index.getIdPair(slideIdParam)
if slideId == "" {
return
}
for {
var slide string
conn.SetDeadline(time.Now().Add(15 * time.Minute))
if err := websocket.Message.Receive(conn, &slide); err != nil {
return
}
curSlide, _ := strconv.Atoi(slide)
registry.setSlide(slideId, curSlide)
}
}