fix client
Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
parent
7f07cdcd2e
commit
0f07f3fc63
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user