2017-06-12 14:11:23 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
|
2017-06-20 00:56:33 +03:00
|
|
|
vnc "github.com/vtolstov/go-vnc"
|
2017-06-12 14:11:23 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Establish TCP connection to VNC server.
|
2017-06-20 00:56:33 +03:00
|
|
|
nc, err := net.Dial("tcp", "192.168.100.41:5900")
|
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)
|
|
|
|
|
|
|
|
ccfg := &vnc.ClientConfig{
|
|
|
|
VersionHandler: vnc.ClientVersionHandler,
|
|
|
|
SecurityHandler: vnc.ClientSecurityHandler,
|
|
|
|
SecurityHandlers: []vnc.SecurityHandler{&vnc.ClientAuthATEN{Username: []byte("ADMIN"), Password: []byte("ADMIN")}},
|
|
|
|
ClientInitHandler: vnc.ClientClientInitHandler,
|
|
|
|
ServerInitHandler: vnc.ClientServerInitHandler,
|
|
|
|
PixelFormat: vnc.PixelFormat32bit,
|
|
|
|
ClientMessageCh: cchClient,
|
|
|
|
ServerMessageCh: cchServer,
|
|
|
|
ServerMessages: vnc.DefaultServerMessages,
|
|
|
|
Encodings: []vnc.Encoding{&vnc.RawEncoding{}},
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Listen and handle server messages.
|
2017-06-20 00:56:33 +03:00
|
|
|
go cc.Handle()
|
2017-06-12 14:11:23 +03:00
|
|
|
|
|
|
|
// Process messages coming in on the ServerMessage channel.
|
|
|
|
for {
|
2017-06-20 00:56:33 +03:00
|
|
|
select {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|