From 0f07f3fc639e8dfb4d2fbcd8643d8685867947d9 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 20 Jun 2017 00:56:33 +0300 Subject: [PATCH] fix client Signed-off-by: Vasiliy Tolstov --- example/client/main.go | 55 ++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/example/client/main.go b/example/client/main.go index 8b6fcdd..17c1e39 100644 --- a/example/client/main.go +++ b/example/client/main.go @@ -4,56 +4,49 @@ import ( "context" "log" "net" - "time" - vnc "github.com/kward/go-vnc" - "github.com/kward/go-vnc/logging" - "github.com/kward/go-vnc/messages" - "github.com/kward/go-vnc/rfbflags" + vnc "github.com/vtolstov/go-vnc" ) func main() { - logging.V(logging.FnDeclLevel) // Establish TCP connection to VNC server. - nc, err := net.Dial("tcp", "127.0.0.1:5923") + nc, err := net.Dial("tcp", "192.168.100.41:5900") if err != nil { log.Fatalf("Error connecting to VNC host. %v", err) } // Negotiate connection with the server. - ch := make(chan vnc.ServerMessage) - vc, err := vnc.Connect(context.Background(), nc, - &vnc.ClientConfig{ - Auth: []vnc.ClientAuth{&vnc.ClientAuthNone{}}, - ServerMessageCh: ch, - }) + 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) if err != nil { log.Fatalf("Error negotiating connection to VNC host. %v", err) } - // Periodically request framebuffer updates. - go func() { - w, h := vc.FramebufferWidth(), vc.FramebufferHeight() - for { - if err := vc.FramebufferUpdateRequest(rfbflags.RFBTrue, 0, 0, w, h); err != nil { - log.Printf("error requesting framebuffer update: %v", err) - return - } - time.Sleep(1 * time.Second) - } - }() - // Listen and handle server messages. - go vc.ListenAndHandle() + go cc.Handle() // Process messages coming in on the ServerMessage channel. for { - msg := <-ch - switch msg.Type() { - case messages.FramebufferUpdate: - log.Println("Received FramebufferUpdate message.") - default: + select { + 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) } }