fixup client

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
Василий Толстов 2017-07-10 23:40:30 +03:00
parent 7915e89e38
commit faf8458fa3

View File

@ -4,13 +4,15 @@ import (
"context"
"log"
"net"
"os"
"time"
vnc "github.com/vtolstov/go-vnc"
)
func main() {
// Establish TCP connection to VNC server.
nc, err := net.Dial("tcp", "192.168.100.41:5900")
nc, err := net.DialTimeout("tcp", os.Args[1], 5*time.Second)
if err != nil {
log.Fatalf("Error connecting to VNC host. %v", err)
}
@ -18,18 +20,16 @@ func main() {
// Negotiate connection with the server.
cchServer := make(chan vnc.ServerMessage)
cchClient := make(chan vnc.ClientMessage)
errorCh := make(chan error)
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,
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,
}
cc, err := vnc.Connect(context.Background(), nc, ccfg)
@ -37,17 +37,16 @@ func main() {
if err != nil {
log.Fatalf("Error negotiating connection to VNC host. %v", err)
}
// Listen and handle server messages.
go cc.Handle()
// Process messages coming in on the ServerMessage channel.
for {
select {
case err := <-errorCh:
panic(err)
case msg := <-cchClient:
log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg)
case msg := <-cchServer:
log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg)
}
}
cc.Wait()
}