2017-06-12 14:11:23 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"net"
|
2017-07-10 23:40:30 +03:00
|
|
|
"os"
|
|
|
|
"time"
|
2017-06-12 14:11:23 +03:00
|
|
|
|
2018-07-27 16:55:06 +03:00
|
|
|
vnc "github.com/sdstack/go-rfb"
|
2017-06-12 14:11:23 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Establish TCP connection to VNC server.
|
2017-07-10 23:40:30 +03:00
|
|
|
nc, err := net.DialTimeout("tcp", os.Args[1], 5*time.Second)
|
2017-06-12 14:11:23 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error connecting to VNC host. %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Negotiate connection with the server.
|
2017-06-20 00:56:33 +03:00
|
|
|
cchServer := make(chan vnc.ServerMessage)
|
|
|
|
cchClient := make(chan vnc.ClientMessage)
|
2017-07-10 23:40:30 +03:00
|
|
|
errorCh := make(chan error)
|
2017-06-20 00:56:33 +03:00
|
|
|
|
|
|
|
ccfg := &vnc.ClientConfig{
|
2017-07-10 23:40:30 +03:00
|
|
|
SecurityHandlers: []vnc.SecurityHandler{&vnc.ClientAuthATEN{Username: []byte(os.Args[2]), Password: []byte(os.Args[3])}},
|
|
|
|
PixelFormat: vnc.PixelFormat32bit,
|
|
|
|
ClientMessageCh: cchClient,
|
|
|
|
ServerMessageCh: cchServer,
|
|
|
|
ServerMessages: vnc.DefaultServerMessages,
|
|
|
|
Encodings: []vnc.Encoding{&vnc.RawEncoding{}},
|
|
|
|
ErrorCh: errorCh,
|
2017-06-20 00:56:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cc, err := vnc.Connect(context.Background(), nc, ccfg)
|
2017-06-12 14:11:23 +03:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error negotiating connection to VNC host. %v", err)
|
|
|
|
}
|
|
|
|
// Process messages coming in on the ServerMessage channel.
|
|
|
|
for {
|
2017-06-20 00:56:33 +03:00
|
|
|
select {
|
2017-07-10 23:40:30 +03:00
|
|
|
case err := <-errorCh:
|
|
|
|
panic(err)
|
2017-06-20 00:56:33 +03:00
|
|
|
case msg := <-cchClient:
|
|
|
|
log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg)
|
|
|
|
case msg := <-cchServer:
|
2017-06-12 14:11:23 +03:00
|
|
|
log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg)
|
|
|
|
}
|
|
|
|
}
|
2017-07-10 23:40:30 +03:00
|
|
|
cc.Wait()
|
2017-06-12 14:11:23 +03:00
|
|
|
}
|