func startServer2() { server, err := NewServer() if err != nil { log.Error(err.Error()) return } defer func() { server.Close() }() serve := func(ws *websocket.Conn) { log.Debug("new agent") if err := server.Serve(fw.NewWsReadWriter(ws)); err != nil { log.Error(err.Error()) } log.Debug("agent leave") } http.Handle("/", websocket.Handler(serve)) http.ListenAndServe(cfg.AgentAddr(), nil) log.Info("server2 serve on ", cfg.AgentAddr()) }
func TestClient1(t *testing.T) { ctrl := make(chan string, 1) cli, err := fw.NewClient(cfg.AgentAddr(), &cowrobot.Clientmodel{}, ctrl) if err != nil { t.Error(err.Error()) return } t.Log(cli) go cli.Loop() s := string(`{"cmd":104,"content":"{\"account\":\"testUtf\",\"psw\":\"pswlk22\"}"}`) cli.Send(s) time.Sleep(10 * time.Second) t.Log("end") }
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 }