本文整理匯總了Golang中github.com/henrylee2cn/websocket/google.Conn類的典型用法代碼示例。如果您正苦於以下問題:Golang Conn類的具體用法?Golang Conn怎麽用?Golang Conn使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Conn類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: wsLogHandle
// log發送api
func wsLogHandle(conn *ws.Conn) {
var err error
defer func() {
reporter.Printf("websocket log發送出錯斷開 (%v) !", err)
}()
Log.logChan = make(chan string, 1024)
go func(conn *ws.Conn) {
defer func() {
close(Log.logChan)
conn.Close()
}()
for {
if err := ws.JSON.Receive(conn, nil); err != nil {
reporter.Printf("websocket log接收出錯斷開 (%v) !", err)
return
}
}
}(conn)
for msg := range Log.logChan {
if _, err = ws.Message.Send(conn, msg); err != nil {
return
}
}
}
示例2: wsHandle
func wsHandle(conn *ws.Conn) {
sess, _ := globalSessions.SessionStart(nil, conn.Request())
sessID := sess.SessionID()
if Sc.connPool[sessID] == nil {
Sc.Add(sessID, conn)
}
defer Sc.Remove(sessID, conn)
go func() {
var err error
for info := range Sc.wchanPool[sessID].wchan {
if _, err = ws.JSON.Send(conn, info); err != nil {
return
}
}
}()
for {
var req map[string]interface{}
if err := ws.JSON.Receive(conn, &req); err != nil {
// logs.Log.Debug("websocket接收出錯斷開 (%v) !", err)
return
}
// log.Log.Debug("Received from web: %v", req)
wsApi[util.Atoa(req["operate"])](sessID, req)
}
}
示例3: wsHandle
func wsHandle(conn *ws.Conn) {
defer func() {
close(wchan)
conn.Close()
}()
wchan = make(chan interface{}, 1024)
go func(conn *ws.Conn) {
var err error
defer func() {
reporter.Printf("websocket發送出錯斷開 (%v) !", err)
}()
for info := range wchan {
if _, err = ws.JSON.Send(conn, info); err != nil {
return
}
}
}(conn)
for {
var req map[string]interface{}
if err := ws.JSON.Receive(conn, &req); err != nil {
reporter.Printf("websocket接收出錯斷開 (%v) !", err)
return
}
reporter.Printf("Received from web: %v", req)
wsApi[util.Atoa(req["operate"])](conn, req)
}
}
示例4: wsLogHandle
// log發送api
func wsLogHandle(conn *ws.Conn) {
var err error
defer func() {
// reporter.Printf("websocket log發送出錯斷開 (%v) !", err)
}()
// 新建web前端log輸出
Log.Open()
go func(conn *ws.Conn) {
defer func() {
// 關閉web前端log輸出
Log.Close()
// 關閉websocket連接
conn.Close()
}()
for {
if err := ws.JSON.Receive(conn, nil); err != nil {
// reporter.Printf("websocket log接收出錯斷開 (%v) !", err)
return
}
}
}(conn)
for msg := range Log.logChan {
if _, err = ws.Message.Send(conn, msg); err != nil {
return
}
}
}
示例5: wsLogHandle
// log發送api
func wsLogHandle(conn *ws.Conn) {
var err error
sess, _ := globalSessions.SessionStart(nil, conn.Request())
sessID := sess.SessionID()
if Lsc.connPool[sessID] == nil {
Lsc.Add(sessID, conn)
}
go func() {
defer func() {
// 關閉web前端log輸出並斷開websocket連接
Lsc.Remove(sessID, conn)
}()
for {
if err := ws.JSON.Receive(conn, nil); err != nil {
// logs.Log.Debug("websocket log接收出錯斷開 (%v) !", err)
return
}
}
}()
for msg := range Lsc.lvPool[sessID].logChan {
if _, err = ws.Message.Send(conn, msg); err != nil {
return
}
}
}
示例6: wsHandle
func wsHandle(conn *ws.Conn) {
wchanClosed = false
defer func() {
// 連接斷開前關閉正在運行的任務
// if isRunning {
// isRunning = false
// logicApp.LogRest().Stop()
// }
wchanClosed = true
close(wchan)
conn.Close()
}()
wchan = make(chan interface{}, 1024)
go func(conn *ws.Conn) {
var err error
for info := range wchan {
if _, err = ws.JSON.Send(conn, info); err != nil {
return
}
}
}(conn)
for {
var req map[string]interface{}
if err := ws.JSON.Receive(conn, &req); err != nil {
// logs.Log.Debug("websocket接收出錯斷開 (%v) !", err)
return
}
// log.Log.Debug("Received from web: %v", req)
wsApi[util.Atoa(req["operate"])](conn, req)
}
}
示例7: Remove
func (self *LogSocketController) Remove(sessID string, conn *ws.Conn) {
if self.connPool[sessID] == nil {
return
}
lv := self.lvPool[sessID]
lv.closed = true
close(lv.logChan)
conn.Close()
delete(self.connPool, sessID)
delete(self.lvPool, sessID)
}
示例8: Remove
func (self *SocketController) Remove(sessID string, conn *ws.Conn) {
self.rwMutex.Lock()
defer self.rwMutex.Unlock()
if self.connPool[sessID] == nil {
return
}
wc := self.wchanPool[sessID]
close(wc.wchan)
conn.Close()
delete(self.connPool, sessID)
delete(self.wchanPool, sessID)
}