dispatch/server/websocket.go

32 lines
483 B
Go
Raw Normal View History

package server
2015-01-17 01:37:21 +00:00
import (
2015-05-01 22:20:22 +00:00
"github.com/khlieng/name_pending/Godeps/_workspace/src/github.com/gorilla/websocket"
2015-01-17 01:37:21 +00:00
)
type WebSocket struct {
conn *websocket.Conn
Out chan []byte
2015-01-17 01:37:21 +00:00
}
func NewWebSocket(ws *websocket.Conn) *WebSocket {
return &WebSocket{
conn: ws,
Out: make(chan []byte, 32),
2015-01-17 01:37:21 +00:00
}
}
func (w *WebSocket) write() {
for {
err := w.conn.WriteMessage(websocket.TextMessage, <-w.Out)
if err != nil {
return
}
2015-01-17 01:37:21 +00:00
}
}
func (w *WebSocket) close() {
close(w.Out)
}