fix client

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
Василий Толстов 2017-06-20 00:56:33 +03:00
parent 7f07cdcd2e
commit 0f07f3fc63

View File

@ -4,56 +4,49 @@ import (
"context" "context"
"log" "log"
"net" "net"
"time"
vnc "github.com/kward/go-vnc" vnc "github.com/vtolstov/go-vnc"
"github.com/kward/go-vnc/logging"
"github.com/kward/go-vnc/messages"
"github.com/kward/go-vnc/rfbflags"
) )
func main() { func main() {
logging.V(logging.FnDeclLevel)
// Establish TCP connection to VNC server. // 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 { if err != nil {
log.Fatalf("Error connecting to VNC host. %v", err) log.Fatalf("Error connecting to VNC host. %v", err)
} }
// Negotiate connection with the server. // Negotiate connection with the server.
ch := make(chan vnc.ServerMessage) cchServer := make(chan vnc.ServerMessage)
vc, err := vnc.Connect(context.Background(), nc, cchClient := make(chan vnc.ClientMessage)
&vnc.ClientConfig{
Auth: []vnc.ClientAuth{&vnc.ClientAuthNone{}}, ccfg := &vnc.ClientConfig{
ServerMessageCh: ch, 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 { if err != nil {
log.Fatalf("Error negotiating connection to VNC host. %v", err) 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. // Listen and handle server messages.
go vc.ListenAndHandle() go cc.Handle()
// Process messages coming in on the ServerMessage channel. // Process messages coming in on the ServerMessage channel.
for { for {
msg := <-ch select {
switch msg.Type() { case msg := <-cchClient:
case messages.FramebufferUpdate: log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg)
log.Println("Received FramebufferUpdate message.") case msg := <-cchServer:
default:
log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg) log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg)
} }
} }