not working example

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
2017-06-12 14:11:23 +03:00
parent 5139d1dd82
commit a45bca15e3
19 changed files with 2078 additions and 0 deletions

60
example/client/main.go Normal file
View File

@@ -0,0 +1,60 @@
package main
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"
)
func main() {
logging.V(logging.FnDeclLevel)
// Establish TCP connection to VNC server.
nc, err := net.Dial("tcp", "127.0.0.1:5923")
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,
})
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()
// Process messages coming in on the ServerMessage channel.
for {
msg := <-ch
switch msg.Type() {
case messages.FramebufferUpdate:
log.Println("Received FramebufferUpdate message.")
default:
log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg)
}
}
}

70
example/proxy/main.go Normal file
View File

@@ -0,0 +1,70 @@
package main
import (
"context"
"flag"
"log"
"net"
"os"
"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"
)
func main() {
flag.Parse()
logging.V(logging.FnDeclLevel)
ln, err := net.Listen("tcp", os.Args[1])
if err != nil {
log.Fatalf("Error listen. %v", err)
}
// Negotiate connection with the server.
sch := make(chan vnc.ClientMessage)
// handle client messages.
vcc := vnc.NewServerConfig()
vcc.Auth = []vnc.ServerAuth{&vnc.ServerAuthNone{}}
vcc.ClientMessageCh = sch
go vnc.Serve(context.Background(), ln, vcc)
nc, err := net.Dial("tcp", os.Args[1])
if err != nil {
log.Fatalf("Error connecting to VNC host. %v", err)
}
// Negotiate connection with the server.
cch := make(chan vnc.ServerMessage)
vc, err := vnc.Connect(context.Background(), nc,
&vnc.ClientConfig{
Auth: []vnc.ClientAuth{&vnc.ClientAuthNone{}},
ServerMessageCh: cch,
})
if err != nil {
log.Fatalf("Error negotiating connection to VNC host. %v", err)
}
// Listen and handle server messages.
go vc.ListenAndHandle()
// Process messages coming in on the ServerMessage channel.
for {
msg := <-ch
switch msg.Type() {
case messages.FramebufferUpdate:
log.Println("Received FramebufferUpdate message.")
default:
log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg)
}
}
// Process messages coming in on the ClientMessage channel.
for {
msg := <-ch
msg.Write(
}
}

42
example/server/main.go Normal file
View File

@@ -0,0 +1,42 @@
package main
import (
"context"
"log"
"net"
vnc "github.com/vtolstov/go-vnc"
)
func main() {
ln, err := net.Listen("tcp", ":5900")
if err != nil {
log.Fatalf("Error listen. %v", err)
}
chServer := make(chan vnc.ClientMessage)
chClient := make(chan vnc.ServerMessage)
cfg := &vnc.ServerConfig{
VersionHandler: vnc.ServerVersionHandler,
SecurityHandler: vnc.ServerSecurityHandler,
SecurityHandlers: []vnc.ServerHandler{vnc.ServerSecurityNoneHandler},
ClientInitHandler: vnc.ServerClientInitHandler,
ServerInitHandler: vnc.ServerServerInitHandler,
Encodings: []vnc.Encoding{&vnc.RawEncoding{}},
PixelFormat: vnc.PixelFormat32bit,
ClientMessageCh: chServer,
ServerMessageCh: chClient,
ClientMessages: vnc.DefaultClientMessages,
}
go vnc.Serve(context.Background(), ln, cfg)
// Process messages coming in on the ClientMessage channel.
for {
msg := <-chClient
switch msg.Type() {
default:
log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg)
}
}
}