Exemplo n.º 1
0
func (w *WsClient) Write(msg string) (err error) {
	err = websocket.Message.Send(w.ws, msg)
	if err != nil {
		log.Errorf("WS-SEND ERROR: %+v", err.Error())
	} else {
		log.Debugf("WS-SEND: %#v\n", msg)
	}
	return
}
Exemplo n.º 2
0
func (w *WsClient) Read(msg *string) (err error) {
	err = websocket.Message.Receive(w.ws, msg)
	if err != nil {
		log.Errorf("WS-RECV ERROR: %+v", err.Error())
	} else {
		log.Debugf("WS-RECV: %#v\n", *msg)
	}
	return
}
Exemplo n.º 3
0
func newClient() (*websocket.Conn, error) {
	//todo
L:
	client, err := net.Dial("tcp", cfg.AgentAddr())
	if err != nil {
		log.Warning("not connected to agent server, try again ...")
		time.Sleep(1 * time.Second)
		goto L
	}
	conn, err := websocket.NewClient(newConfig_("/"), client)
	if err != nil {
		log.Errorf("WebSocket handshake error: %v", err)
		return nil, err
	}
	return conn, nil
}
Exemplo n.º 4
0
func NewClient(addr string, m ClientModel, out chan string) (*Client, error) {
L:
	client, err := net.Dial("tcp", addr)
	if err != nil {
		log.Warningf("not connected to %+v, try again ...", addr)
		time.Sleep(1 * time.Second)
		goto L
	}
	conn, err := websocket.NewClient(newConfig("/"), client)
	if err != nil {
		log.Errorf("WebSocket handshake error: %v", err)
		return nil, err
	}
	rwc := NewWsReadWriter(conn)
	return &Client{
		ReadWriteCloser: rwc,
		ClientModel:     m,
		send:            make(chan string, 10),
		ctrl:            out,
	}, nil
}