@@ -2,69 +2,111 @@ 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"
|
||||
vnc "github.com/vtolstov/go-vnc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
logging.V(logging.FnDeclLevel)
|
||||
ln, err := net.Listen("tcp", os.Args[1])
|
||||
ln, err := net.Listen("tcp", ":5900")
|
||||
if err != nil {
|
||||
log.Fatalf("Error listen. %v", err)
|
||||
}
|
||||
|
||||
// Negotiate connection with the server.
|
||||
sch := make(chan vnc.ClientMessage)
|
||||
schServer := make(chan vnc.ClientMessage)
|
||||
schClient := make(chan vnc.ServerMessage)
|
||||
|
||||
// handle client messages.
|
||||
vcc := vnc.NewServerConfig()
|
||||
vcc.Auth = []vnc.ServerAuth{&vnc.ServerAuthNone{}}
|
||||
vcc.ClientMessageCh = sch
|
||||
go vnc.Serve(context.Background(), ln, vcc)
|
||||
scfg := &vnc.ServerConfig{
|
||||
Width: 800,
|
||||
Height: 600,
|
||||
VersionHandler: vnc.ServerVersionHandler,
|
||||
SecurityHandler: vnc.ServerSecurityHandler,
|
||||
SecurityHandlers: []vnc.SecurityHandler{&vnc.ClientAuthNone{}},
|
||||
ClientInitHandler: vnc.ServerClientInitHandler,
|
||||
ServerInitHandler: vnc.ServerServerInitHandler,
|
||||
Encodings: []vnc.Encoding{&vnc.RawEncoding{}},
|
||||
PixelFormat: vnc.PixelFormat24bit,
|
||||
ClientMessageCh: schServer,
|
||||
ServerMessageCh: schClient,
|
||||
ClientMessages: vnc.DefaultClientMessages,
|
||||
DesktopName: []byte("vnc proxy"),
|
||||
}
|
||||
go vnc.Serve(context.Background(), ln, scfg)
|
||||
|
||||
nc, err := net.Dial("tcp", os.Args[1])
|
||||
c, err := net.Dial("tcp", "127.0.0.1:5944")
|
||||
if err != nil {
|
||||
log.Fatalf("Error connecting to VNC host. %v", err)
|
||||
log.Fatalf("Error dial. %v", err)
|
||||
}
|
||||
cchServer := make(chan vnc.ServerMessage)
|
||||
cchClient := make(chan vnc.ClientMessage)
|
||||
|
||||
ccfg := &vnc.ClientConfig{
|
||||
VersionHandler: vnc.ClientVersionHandler,
|
||||
SecurityHandler: vnc.ClientSecurityHandler,
|
||||
SecurityHandlers: []vnc.SecurityHandler{&vnc.ClientAuthNone{}},
|
||||
ClientInitHandler: vnc.ClientClientInitHandler,
|
||||
ServerInitHandler: vnc.ClientServerInitHandler,
|
||||
PixelFormat: vnc.PixelFormat24bit,
|
||||
ClientMessageCh: cchClient,
|
||||
ServerMessageCh: cchServer,
|
||||
ServerMessages: vnc.DefaultServerMessages,
|
||||
Encodings: []vnc.Encoding{&vnc.RawEncoding{}},
|
||||
}
|
||||
|
||||
// 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,
|
||||
})
|
||||
|
||||
cc, err := vnc.Connect(context.Background(), c, ccfg)
|
||||
if err != nil {
|
||||
log.Fatalf("Error negotiating connection to VNC host. %v", err)
|
||||
log.Fatalf("Error dial. %v", err)
|
||||
}
|
||||
defer cc.Close()
|
||||
go cc.Handle()
|
||||
|
||||
// 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)
|
||||
select {
|
||||
case msg := <-cchClient:
|
||||
switch msg.Type() {
|
||||
default:
|
||||
log.Printf("00 Received message type:%v msg:%v\n", msg.Type(), msg)
|
||||
}
|
||||
case msg := <-cchServer:
|
||||
switch msg.Type() {
|
||||
default:
|
||||
log.Printf("01 Received message type:%v msg:%v\n", msg.Type(), msg)
|
||||
}
|
||||
case msg := <-schClient:
|
||||
switch msg.Type() {
|
||||
default:
|
||||
log.Printf("10 Received message type:%v msg:%v\n", msg.Type(), msg)
|
||||
}
|
||||
case msg := <-schServer:
|
||||
log.Printf("11 Received message type:%v msg:%v\n", msg.Type(), msg)
|
||||
switch msg.Type() {
|
||||
case vnc.SetEncodingsMsgType:
|
||||
encRaw := &vnc.RawEncoding{}
|
||||
msg1 := &vnc.SetEncodings{
|
||||
MsgType: vnc.SetEncodingsMsgType,
|
||||
EncNum: 1,
|
||||
Encodings: []vnc.EncodingType{encRaw.Type()},
|
||||
}
|
||||
if err := msg1.Write(cc); err != nil {
|
||||
log.Fatalf("err %v\n", err)
|
||||
}
|
||||
msg2 := &vnc.FramebufferUpdateRequest{
|
||||
MsgType: vnc.FramebufferUpdateRequestMsgType,
|
||||
Inc: 0,
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: cc.Width(),
|
||||
Height: cc.Height(),
|
||||
}
|
||||
if err := msg2.Write(cc); err != nil {
|
||||
log.Fatalf("err %v\n", err)
|
||||
}
|
||||
default:
|
||||
if err := msg.Write(cc); err != nil {
|
||||
log.Fatalf("err %v\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process messages coming in on the ClientMessage channel.
|
||||
for {
|
||||
msg := <-ch
|
||||
msg.Write(
|
||||
}
|
||||
}
|
||||
|
@@ -2,8 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"image"
|
||||
"log"
|
||||
"math"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
vnc "github.com/vtolstov/go-vnc"
|
||||
)
|
||||
@@ -17,10 +21,16 @@ func main() {
|
||||
chServer := make(chan vnc.ClientMessage)
|
||||
chClient := make(chan vnc.ServerMessage)
|
||||
|
||||
im := image.NewRGBA(image.Rect(0, 0, width, height))
|
||||
tick := time.NewTicker(time.Second / 2)
|
||||
defer tick.Stop()
|
||||
|
||||
cfg := &vnc.ServerConfig{
|
||||
Width: 800,
|
||||
Height: 600,
|
||||
VersionHandler: vnc.ServerVersionHandler,
|
||||
SecurityHandler: vnc.ServerSecurityHandler,
|
||||
SecurityHandlers: []vnc.ServerHandler{vnc.ServerSecurityNoneHandler},
|
||||
SecurityHandlers: []vnc.SecurityHandler{&vnc.ClientAuthNone{}},
|
||||
ClientInitHandler: vnc.ServerClientInitHandler,
|
||||
ServerInitHandler: vnc.ServerServerInitHandler,
|
||||
Encodings: []vnc.Encoding{&vnc.RawEncoding{}},
|
||||
@@ -33,10 +43,51 @@ func main() {
|
||||
|
||||
// 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)
|
||||
select {
|
||||
case <-tick.C:
|
||||
drawImage(im, 0)
|
||||
fmt.Printf("tick\n")
|
||||
case msg := <-chClient:
|
||||
switch msg.Type() {
|
||||
default:
|
||||
log.Printf("11 Received message type:%v msg:%v\n", msg.Type(), msg)
|
||||
}
|
||||
case msg := <-chServer:
|
||||
switch msg.Type() {
|
||||
default:
|
||||
log.Printf("22 Received message type:%v msg:%v\n", msg.Type(), msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
width = 800
|
||||
height = 600
|
||||
)
|
||||
|
||||
func drawImage(im *image.RGBA, anim int) {
|
||||
pos := 0
|
||||
const border = 50
|
||||
for y := 0; y < height; y++ {
|
||||
for x := 0; x < width; x++ {
|
||||
var r, g, b uint8
|
||||
switch {
|
||||
case x < border*2.5 && x < int((1.1+math.Sin(float64(y+anim*2)/40))*border):
|
||||
r = 255
|
||||
case x > width-border*2.5 && x > width-int((1.1+math.Sin(math.Pi+float64(y+anim*2)/40))*border):
|
||||
g = 255
|
||||
case y < border*2.5 && y < int((1.1+math.Sin(float64(x+anim*2)/40))*border):
|
||||
r, g = 255, 255
|
||||
case y > height-border*2.5 && y > height-int((1.1+math.Sin(math.Pi+float64(x+anim*2)/40))*border):
|
||||
b = 255
|
||||
default:
|
||||
r, g, b = uint8(x+anim), uint8(y+anim), uint8(x+y+anim*3)
|
||||
}
|
||||
im.Pix[pos] = r
|
||||
im.Pix[pos+1] = g
|
||||
im.Pix[pos+2] = b
|
||||
pos += 4 // skipping alpha
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user