-
-
Save caugello/c3d4db7858ee8ed0bf25d30e68673619 to your computer and use it in GitHub Desktop.
Revisions
-
x32net revised this gist
Jun 7, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ // Go Websocket binary proxy noVnc package main import ( -
x32net renamed this gist
Jun 7, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
bit4bit created this gist
Jun 30, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ package main import ( "flag" "golang.org/x/net/websocket" "io" "log" "net" "net/http" "os" ) var ( sourceAddr = flag.String("source", "", "source address") targeAddr = flag.String("target", "", "target address") ) func main() { flag.Parse() if *sourceAddr == "" || *targeAddr == "" { flag.PrintDefaults() os.Exit(1) } mux := websocket.Server{ Handshake: bootHandshake, Handler: handleWss} http.Handle("/websockify", mux) err := http.ListenAndServe(*sourceAddr, nil) if err != nil { log.Fatal(err) } } func handleWss(wsconn *websocket.Conn) { log.Println("handlewss") conn, err := net.Dial("tcp", *targeAddr) if err != nil { log.Println(err) wsconn.Close() } else { wsconn.PayloadType = websocket.BinaryFrame go io.Copy(conn, wsconn) go io.Copy(wsconn, conn) select {} } } func bootHandshake(config *websocket.Config, r *http.Request) error { config.Protocol = []string{"binary"} r.Header.Set("Access-Control-Allow-Origin", "*") r.Header.Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE") return nil }