agent/wsclient/client.go
func (cs *ClientServerImpl) ConsumeMessages() error {
	for {
		if err := cs.SetReadDeadline(time.Now().Add(cs.RWTimeout)); err != nil {
			return err
		}
		messageType, message, err := cs.conn.ReadMessage()

		switch {
		case err == nil:
			if messageType != websocket.TextMessage {
				// maybe not fatal though, we'll try to process it anyways
				seelog.Errorf("Unexpected messageType: %v", messageType)
			}
			cs.handleMessage(message)

		case permissibleCloseCode(err):
			seelog.Debugf("Connection closed for a valid reason: %s", err)
			return io.EOF

		default:
			// Unexpected error occurred
			seelog.Errorf("Error getting message from ws backend: error: [%v], messageType: [%v] ",
				err, messageType)
			return err
		}

	}
}
func (cs *ClientServerImpl) ConsumeMessages() error {
	for {
		if err := cs.SetReadDeadline(time.Now().Add(cs.RWTimeout)); err != nil {
			return err
		}
		messageType, message, err := cs.conn.ReadMessage()

		switch {
		case err == nil:
			if messageType != websocket.TextMessage {
				// maybe not fatal though, we'll try to process it anyways
				seelog.Errorf("Unexpected messageType: %v", messageType)
			}
			cs.handleMessage(message)

		case permissibleCloseCode(err):
			seelog.Debugf("Connection closed for a valid reason: %s", err)
			return io.EOF

		default:
			// Unexpected error occurred
			seelog.Errorf("Error getting message from ws backend: error: [%v], messageType: [%v] ",
				err, messageType)
			return err
		}

	}
}
// ConsumeMessages reads messages from the websocket connection and handles read
// messages from an active connection.