2017-06-12 14:11:23 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
|
2017-06-13 01:52:07 +03:00
|
|
|
vnc "github.com/vtolstov/go-vnc"
|
2017-06-12 14:11:23 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-06-13 01:52:07 +03:00
|
|
|
ln, err := net.Listen("tcp", ":5900")
|
2017-06-12 14:11:23 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error listen. %v", err)
|
|
|
|
}
|
|
|
|
|
2017-06-13 16:20:35 +03:00
|
|
|
schClient := make(chan vnc.ClientMessage)
|
|
|
|
schServer := make(chan vnc.ServerMessage)
|
2017-06-12 14:11:23 +03:00
|
|
|
|
2017-06-13 01:52:07 +03:00
|
|
|
scfg := &vnc.ServerConfig{
|
2017-06-18 19:42:41 +03:00
|
|
|
Width: 800,
|
|
|
|
Height: 600,
|
|
|
|
VersionHandler: vnc.ServerVersionHandler,
|
|
|
|
SecurityHandler: vnc.ServerSecurityHandler,
|
|
|
|
SecurityHandlers: []vnc.SecurityHandler{
|
|
|
|
&vnc.ClientAuthVeNCrypt02Plain{Username: []byte("test"), Password: []byte("test")},
|
|
|
|
&vnc.ClientAuthNone{},
|
|
|
|
},
|
2017-06-13 01:52:07 +03:00
|
|
|
ClientInitHandler: vnc.ServerClientInitHandler,
|
|
|
|
ServerInitHandler: vnc.ServerServerInitHandler,
|
2017-06-18 19:42:41 +03:00
|
|
|
Encodings: []vnc.Encoding{
|
|
|
|
&vnc.TightPngEncoding{},
|
|
|
|
&vnc.CopyRectEncoding{},
|
|
|
|
&vnc.RawEncoding{},
|
|
|
|
},
|
|
|
|
PixelFormat: vnc.PixelFormat32bit,
|
|
|
|
ClientMessageCh: schClient,
|
|
|
|
ServerMessageCh: schServer,
|
|
|
|
ClientMessages: vnc.DefaultClientMessages,
|
|
|
|
DesktopName: []byte("vnc proxy"),
|
2017-06-13 01:52:07 +03:00
|
|
|
}
|
2017-06-13 16:20:35 +03:00
|
|
|
c, err := net.Dial("tcp", "127.0.0.1:5995")
|
2017-06-12 14:11:23 +03:00
|
|
|
if err != nil {
|
2017-06-13 01:52:07 +03:00
|
|
|
log.Fatalf("Error dial. %v", err)
|
2017-06-12 14:11:23 +03:00
|
|
|
}
|
2017-06-13 01:52:07 +03:00
|
|
|
cchServer := make(chan vnc.ServerMessage)
|
|
|
|
cchClient := make(chan vnc.ClientMessage)
|
2017-06-12 14:11:23 +03:00
|
|
|
|
2017-06-13 01:52:07 +03:00
|
|
|
ccfg := &vnc.ClientConfig{
|
|
|
|
VersionHandler: vnc.ClientVersionHandler,
|
|
|
|
SecurityHandler: vnc.ClientSecurityHandler,
|
|
|
|
SecurityHandlers: []vnc.SecurityHandler{&vnc.ClientAuthNone{}},
|
|
|
|
ClientInitHandler: vnc.ClientClientInitHandler,
|
|
|
|
ServerInitHandler: vnc.ClientServerInitHandler,
|
2017-06-13 16:20:35 +03:00
|
|
|
PixelFormat: vnc.PixelFormat32bit,
|
2017-06-13 01:52:07 +03:00
|
|
|
ClientMessageCh: cchClient,
|
|
|
|
ServerMessageCh: cchServer,
|
|
|
|
ServerMessages: vnc.DefaultServerMessages,
|
|
|
|
Encodings: []vnc.Encoding{&vnc.RawEncoding{}},
|
|
|
|
}
|
2017-06-12 14:11:23 +03:00
|
|
|
|
2017-06-13 01:52:07 +03:00
|
|
|
cc, err := vnc.Connect(context.Background(), c, ccfg)
|
2017-06-12 14:11:23 +03:00
|
|
|
if err != nil {
|
2017-06-13 01:52:07 +03:00
|
|
|
log.Fatalf("Error dial. %v", err)
|
2017-06-12 14:11:23 +03:00
|
|
|
}
|
2017-06-13 16:20:35 +03:00
|
|
|
|
2017-06-18 19:42:41 +03:00
|
|
|
// scfg.Width = cc.Width()
|
|
|
|
// scfg.Height = cc.Height()
|
|
|
|
// scfg.PixelFormat = cc.PixelFormat()
|
2017-06-13 16:20:35 +03:00
|
|
|
go vnc.Serve(context.Background(), ln, scfg)
|
|
|
|
|
2017-06-13 01:52:07 +03:00
|
|
|
defer cc.Close()
|
|
|
|
go cc.Handle()
|
2017-06-12 14:11:23 +03:00
|
|
|
|
|
|
|
for {
|
2017-06-13 01:52:07 +03:00
|
|
|
select {
|
|
|
|
case msg := <-cchServer:
|
|
|
|
switch msg.Type() {
|
|
|
|
default:
|
2017-06-13 16:20:35 +03:00
|
|
|
schServer <- msg
|
2017-06-13 01:52:07 +03:00
|
|
|
}
|
|
|
|
case msg := <-schClient:
|
|
|
|
switch msg.Type() {
|
|
|
|
case vnc.SetEncodingsMsgType:
|
2017-06-18 19:42:41 +03:00
|
|
|
var encTypes []vnc.EncodingType
|
|
|
|
for _, enc := range scfg.Encodings {
|
|
|
|
encTypes = append(encTypes, enc.Type())
|
2017-06-13 16:20:35 +03:00
|
|
|
}
|
2017-06-18 19:42:41 +03:00
|
|
|
msg0 := &vnc.SetEncodings{
|
|
|
|
Encodings: encTypes,
|
2017-06-13 01:52:07 +03:00
|
|
|
}
|
2017-06-18 19:42:41 +03:00
|
|
|
cchClient <- msg0
|
2017-06-13 16:20:35 +03:00
|
|
|
/*
|
2017-06-18 19:42:41 +03:00
|
|
|
if scfg.Width != cc.Width() || scfg.Height != cc.Height() {
|
|
|
|
msg1 := &vnc.FramebufferUpdate{
|
|
|
|
Rects: []*vnc.Rectangle{&vnc.Rectangle{
|
|
|
|
Width: cc.Width(),
|
|
|
|
Height: cc.Height(),
|
|
|
|
EncType: vnc.EncDesktopSizePseudo,
|
|
|
|
Enc: &vnc.DesktopSizePseudoEncoding{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
schServer <- msg1
|
2017-06-13 16:20:35 +03:00
|
|
|
}
|
|
|
|
*/
|
2017-06-13 01:52:07 +03:00
|
|
|
default:
|
2017-06-13 16:20:35 +03:00
|
|
|
cchClient <- msg
|
2017-06-13 01:52:07 +03:00
|
|
|
}
|
2017-06-12 14:11:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|