Exemplo n.º 1
0
func testCounter() {

	rclient := remoton.Client{Prefix: "/remoton"}
	session, err := rclient.NewSession("http://localhost:3000", "public")
	if err != nil {
		panic(err)
	}

	defer session.Destroy()
	listener := session.Listen("counter")
	println("Listen Counter")
	for {
		conn, err := listener.Accept()
		if err != nil {
			panic(err)
		}
		println("\tNew connection to counter")
		go func(conn net.Conn) {
			var counter byte

			for {
				_, err := conn.Write([]byte{counter})
				if err != nil {
					println("\tClose connection")
					break
				}

				counter += 1
			}

		}(conn)

	}
}
Exemplo n.º 2
0
func testRpc() {
	rclient := remoton.Client{Prefix: "/remoton"}
	session, err := rclient.NewSession("http://localhost:3000", "public")
	if err != nil {
		panic(err)
	}

	defer session.Destroy()
	listener := session.Listen("rpc")
	println("Listen RPC")
	arith := new(Arith)
	srv := rpc.NewServer()
	srv.Register(arith)
	srv.Accept(listener)
}
Exemplo n.º 3
0
func main() {
	flag.Parse()

	if *authToken == "" {
		log.Error("need auth token please use -auth")
		return
	}

	rclient := remoton.Client{Prefix: *srvPrefix, TLSConfig: &tls.Config{
		InsecureSkipVerify: true,
	}}
	session, err := rclient.NewSession("https://"+*srv, *authToken)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Session -> %s:%s", session.ID, session.AuthToken)
	defer session.Destroy()

	if *chat {
		log.Println("Enable terminal chat")
		lChat := session.Listen("chat")

		go func(listener net.Listener) {
			for {
				wsconn, err := listener.Accept()
				if err != nil {
					log.Error("chat:", err)
					break
				}
				go chatStd(wsconn)
			}
		}(lChat)

	}

	listener := session.Listen(*service)
	if err != nil {
		log.Fatal(err)
	}

	for {
		wsconn, err := listener.Accept()
		if err != nil {
			log.Error(err)
			break
		}

		go func(wsconn net.Conn) {
			conn, err := net.Dial("tcp", *tunnelAddr)
			if err != nil {
				listener.Close()
				log.Error(err)
				return
			}

			errc := make(chan error, 2)
			cp := func(dst net.Conn, src net.Conn) {
				_, err := io.Copy(dst, src)
				errc <- err
			}

			go cp(conn, wsconn)
			go cp(wsconn, conn)

			log.Error(<-errc)
			conn.Close()
			wsconn.Close()
		}(wsconn)
	}
}