예제 #1
0
// 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
0
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)
	}
}
예제 #3
0
// 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
		}
	}
}
예제 #4
0
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)
	}
}
예제 #5
0
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)
}
예제 #6
0
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)
}