예제 #1
0
func (c *wsClient) handlerControlMessage(bFrame []byte) error {
	msg := ctrl.WebSocketControlFrame{}

	if err := json.Unmarshal(bFrame, &msg); err != nil {
		log.Warn("Recve a Text-Frame not JSON format. err=%v, frame=%v", err.Error(), string(bFrame))
		return err
	}
	log.Debug("TCP[%v] Get Frame T[%v], Content=%v, index=%v, ", c, msg.TypeStr(), msg.Content, msg.Index)

	switch msg.Type {
	case ctrl.Msg_Request_Finish:
		c.closeWriter()
	case ctrl.Msg_Client_Busy:
		c.writerForward.Write([]byte("current client was busy, pls try anthor."))
		c.closeWriter()
	case ctrl.Msg_Sys_Err:
		c.writerForward.Write([]byte(msg.Content))
		c.closeWriter()
	case ctrl.Msg_Get_Config:
		log.Info("Get the Client- side local network server config[%s]", msg.Content)
		pConfig.client_conf_forward_host = msg.Content
	default:
		log.Warn("no handler Msg T[%s]", msg.TypeStr())
	}
	return nil
}
예제 #2
0
func (c *wsClient) tellClientSetConfig(svr string) error {
	frame := ctrl.WebSocketControlFrame{
		Type:    ctrl.Msg_Set_Config,
		Index:   0,
		Content: svr,
	}
	return c.websocket.WriteString(frame.Bytes())
}
예제 #3
0
func (c *Client) telServConfig() error {
	frame := ctrl.WebSocketControlFrame{
		Type:    ctrl.Msg_Get_Config,
		Index:   0,
		Content: pConfig.LocalHostServ,
	}
	return c.webSocket.WriteString(frame.Bytes())
}
예제 #4
0
func (c *Client) tellServError(err error) error {
	frame := ctrl.WebSocketControlFrame{
		Type:    ctrl.Msg_Sys_Err,
		Index:   0,
		Content: err.Error(),
	}
	return c.webSocket.WriteString(frame.Bytes())
}
예제 #5
0
func (c *Client) handlerControlFrame(bFrame []byte) (err error) {
	msg := ctrl.WebSocketControlFrame{}

	if err = json.Unmarshal(bFrame, &msg); err != nil {
		log.Error("Recve a Text-Frame not JSON format. err=%v, frame=%v", err.Error(), string(bFrame))
		return err
	}
	log.Info("TCP[%v] Get Frame T[%v], Content=%v, index=%v, ", c, msg.TypeStr(), msg.Content, msg.Index)

	switch msg.Type {
	case ctrl.Msg_New_Connection:
		c.newConnect2LoalNetwork()
	case ctrl.Msg_Request_Finish:
		c.closeLocalConnect()
	case ctrl.Msg_Get_Config:
		err = c.telServConfig()
	case ctrl.Msg_Set_Config:
		pConfig.LocalHostServ = msg.Content
		err = c.telServConfig()
	default:
		log.Warn("no handler Msg T[%s]", msg.TypeStr())
	}
	return err
}