Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qemu websocket for VNC #12

Open
joconcepts opened this issue Jun 7, 2017 · 1 comment
Open

Qemu websocket for VNC #12

joconcepts opened this issue Jun 7, 2017 · 1 comment

Comments

@joconcepts
Copy link

joconcepts commented Jun 7, 2017

I want to write a little proxy for accessing the vnc console of qemu via websocket. Qemu starts the websocket on its own, so its just a simple proxy.

When connecting to the proxy url via noVNC I get the following message:

websocketproxy: couldn't dial to remote backend url unexpected EOF

My code looks as follows:

func ConsoleHandler(w http.ResponseWriter, r *http.Request) {
	port, _ := "5700"
	proxy_url := fmt.Sprintf("http://localhost:%d", port)
        p_u, _ := url.Parse(proxy_url)

	if strings.ToLower(r.Header.Get("Connection")) == "upgrade" {
		p_u_ws, _ := url.Parse(strings.Replace(proxy_url, "http", "ws", 1))
		websocketproxy.NewProxy(p_u_ws).ServeHTTP(w, r)
		return
	}
	httputil.NewSingleHostReverseProxy(p_u).ServeHTTP(w, r)
}

func main() {
	r := mux.NewRouter()
	r.HandleFunc("/", ConsoleHandler)

	srv := &http.Server{
		Handler: r,
		Addr:    "127.0.0.1:10001",
	}
	log.Fatal(srv.ListenAndServe())
}

Can anybody give me some hint why that will not work?

@cihangir
Copy link
Contributor

cihangir commented Jun 7, 2017

Seems like your handler is problematic. NewProxy already handles the upgrades and other stuff.

func main() {
        port, _ := "5700"
	proxy_url := fmt.Sprintf("http://localhost:%d", port)
        p_u, _ := url.Parse(proxy_url) // handle the errors

	r := mux.NewRouter()
	r.Handle("/", websocketproxy.NewProxy(p_u))

	srv := &http.Server{
		Handler: r,
		Addr:    "127.0.0.1:10001",
	}
	log.Fatal(srv.ListenAndServe())
}

Please see the example in readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants