Documentation ¶
Overview ¶
Package vnc provides VNC client implementation.
This package implements The Remote Framebuffer Protocol as documented in [RFC 6143](http://tools.ietf.org/html/rfc6143).
A basic VNC client can be created like this:
// Establish TCP connection to VNC server. nc, err := net.Dial("tcp", "127.0.0.1:5900") if err != nil { log.Fatalf("Error connecting to VNC host. %v", err) } // Negotiate connection with the server. vcc := NewClientConfig("some_password") vc, err := Connect(context.Background(), nc, vcc) 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 := v.conn.FramebufferUpdateRequest(vnc.RFBTrue, 0, 0, w, h); err != nil { log.Printf("error requesting framebuffer update: %v", err) } time.Sleep(1*time.Second) } }() // Listen and handle server messages. go vc.ListenAndHandle() // Process messages coming in on the ServerMessage channel. for { msg := <-vcc.ServerMessageCh switch msg.Type() { case FramebufferUpdateMsg: log.Println("Received FramebufferUpdate message.") default: log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg) } }
This example will connect to a VNC server running on the localhost. It will periodically request updates from the server, and listen for and handle incoming FramebufferUpdate messages coming from the server.
Index ¶
- Constants
- func NewVNCError(s string) error
- func SetSettle(s time.Duration)
- func Settle() time.Duration
- type Bell
- type Buffer
- type ButtonMask
- type ClientAuth
- type ClientAuthNone
- type ClientAuthVNC
- type ClientConfig
- type ClientConn
- func (c *ClientConn) ClientCutText(text string) error
- func (c *ClientConn) Close() error
- func (c *ClientConn) DebugMetrics()
- func (c *ClientConn) DesktopName() string
- func (c *ClientConn) Encodable(enc int32) (Encoding, bool)
- func (c *ClientConn) Encodings() Encodings
- func (c *ClientConn) FramebufferHeight() uint16
- func (c *ClientConn) FramebufferUpdateRequest(inc uint8, x, y, w, h uint16) error
- func (c *ClientConn) FramebufferWidth() uint16
- func (c *ClientConn) KeyEvent(keysym uint32, down bool) error
- func (c *ClientConn) ListenAndHandle() error
- func (c *ClientConn) PointerEvent(mask ButtonMask, x, y uint16) error
- func (c *ClientConn) SetDebug(debug bool)
- func (c *ClientConn) SetEncodings(encs Encodings) error
- func (c *ClientConn) SetPixelFormat(pf PixelFormat) error
- type ClientCutTextMessage
- type Color
- type ColorMap
- type DesktopSizePseudoEncoding
- type EncodableFunc
- type Encoding
- type Encodings
- type FramebufferUpdate
- type FramebufferUpdateRequestMessage
- type KeyEventMessage
- type Marshaler
- type PixelFormat
- type PointerEventMessage
- type RawEncoding
- type Rectangle
- type ServerCutText
- type ServerMessage
- type SetColorMapEntries
- type SetEncodingsMessage
- type SetPixelFormatMessage
- type Unmarshaler
- type VNCError
Examples ¶
Constants ¶
const ( PressKey = true ReleaseKey = false )
const ( KeySpace = iota + 0x0020 KeyExclam KeyQuoteDbl KeyNumberSign KeyDollar KeyPercent KeyAmpersand KeyApostrophe KeyParenLeft KeyParenRight KeyAsterisk KeyPlus KeyComma KeyMinus KeyPeriod KeySlash Key0 Key1 Key2 Key3 Key4 Key5 Key6 Key7 Key8 Key9 KeyColon KeySemicolon KeyLess KeyEqual KeyGreater KeyQuestion KeyAt KeyA KeyB KeyC KeyD KeyE KeyF KeyG KeyH KeyI KeyJ KeyK KeyL KeyM KeyN KeyO KeyP KeyQ KeyR KeyS KeyT KeyU KeyV KeyW KeyX KeyY KeyZ KeyBracketLeft KeyBackslash KeyBracketRight KeyAsciiCircum KeyUnderscore KeyGrave Keya Keyb Keyc Keyd Keye Keyf Keyg Keyh Keyi Keyj Keyk Keyl Keym Keyn Keyo Keyp Keyq Keyr Keys Keyt Keyu Keyv Keyw Keyx Keyy Keyz KeyBraceLeft KeyBar KeyBraceRight KeyAsciiTilde )
Latin 1 (byte 3 = 0) ISO/IEC 8859-1 = Unicode U+0020..U+00FF
const ( KeyBackspace = iota + 0xff08 KeyTab KeyLinefeed KeyClear KeyReturn )
const ( KeyPause = 0xff13 KeyScrollLock = 0xff14 KeySysReq = 0xff15 KeyEscape = 0xff1b )
const ( KeyHome = iota + 0xff50 KeyLeft KeyUp KeyRight KeyDown KeyPageUp KeyPageDown KeyEnd KeyInsert = 0xff63 )
const ( KeyF1 = iota + 0xffbe KeyF2 KeyF3 KeyF4 KeyF5 KeyF6 KeyF7 KeyF8 KeyF9 KeyF10 KeyF11 KeyF12 )
const ( KeyShiftLeft = iota + 0xffe1 KeyShiftRight KeyControlLeft KeyControlRight KeyCapsLock KeyAltLeft KeyAltRight KeyDelete = 0xffff )
const ( RFBFalse = uint8(iota) RFBTrue )
const ( Raw = int32(0) CopyRect = int32(1) RRE = int32(2) Hextile = int32(5) TRLE = int32(15) ZRLE = int32(16) ColorPseudo = int32(-239) DesktopSizePseudo = int32(-223) )
const ( // Client ProtocolVersions. PROTO_VERS_UNSUP = "UNSUPPORTED" PROTO_VERS_3_3 = "RFB 003.003\n" PROTO_VERS_3_8 = "RFB 003.008\n" )
const ( FramebufferUpdateMsg = uint8(iota) SetColorMapEntriesMsg BellMsg ServerCutTextMsg )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bell ¶
type Bell struct{}
Bell signals that an audible bell should be made on the client.
func (*Bell) Read ¶
func (*Bell) Read(c *ClientConn) (ServerMessage, error)
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
func (*Buffer) WriteBytes ¶
type ButtonMask ¶
type ButtonMask uint8
ButtonMask represents a mask of pointer presses/releases.
const ( ButtonLeft ButtonMask = 1 << iota ButtonMiddle ButtonRight Button4 Button5 Button6 Button7 Button8 ButtonNone = ButtonMask(0) )
All available button mask components.
type ClientAuth ¶
type ClientAuth interface { // SecurityType returns the byte identifier sent by the server to // identify this authentication scheme. SecurityType() uint8 // Handshake is called when the authentication handshake should be // performed, as part of the general RFB handshake. (see 7.2.1) Handshake(*ClientConn) error }
ClientAuth implements a method of authenticating with a remote server.
type ClientAuthNone ¶
type ClientAuthNone struct{}
ClientAuthNone is the "none" authentication. See 7.2.1.
func (*ClientAuthNone) Handshake ¶
func (*ClientAuthNone) Handshake(conn *ClientConn) error
func (*ClientAuthNone) SecurityType ¶
func (*ClientAuthNone) SecurityType() uint8
type ClientAuthVNC ¶
type ClientAuthVNC struct {
Password string
}
ClientAuthVNC is the standard password authentication. See 7.2.2.
func (*ClientAuthVNC) Handshake ¶
func (auth *ClientAuthVNC) Handshake(conn *ClientConn) error
func (*ClientAuthVNC) SecurityType ¶
func (*ClientAuthVNC) SecurityType() uint8
type ClientConfig ¶
type ClientConfig struct { // A slice of ClientAuth methods. Only the first instance that is // suitable by the server will be used to authenticate. Auth []ClientAuth // Password for servers that require authentication. Password string // Exclusive determines whether the connection is shared with other // clients. If true, then all other clients connected will be // disconnected when a connection is established to the VNC server. Exclusive bool // The channel that all messages received from the server will be // sent on. If the channel blocks, then the goroutine reading data // from the VNC server may block indefinitely. It is up to the user // of the library to ensure that this channel is properly read. // If this is not set, then all messages will be discarded. ServerMessageCh chan ServerMessage // A slice of supported messages that can be read from the server. // This only needs to contain NEW server messages, and doesn't // need to explicitly contain the RFC-required messages. ServerMessages []ServerMessage // contains filtered or unexported fields }
A ClientConfig structure is used to configure a ClientConn. After one has been passed to initialize a connection, it must not be modified.
func NewClientConfig ¶
func NewClientConfig(p string) *ClientConfig
NewClientConfig returns a populated ClientConfig.
type ClientConn ¶
type ClientConn struct {
// contains filtered or unexported fields
}
The ClientConn type holds client connection information.
func Connect ¶
func Connect(ctx context.Context, c net.Conn, cfg *ClientConfig) (*ClientConn, error)
Connect negotiates a connection to a VNC server.
func NewClientConn ¶
func NewClientConn(c net.Conn, cfg *ClientConfig) *ClientConn
func (*ClientConn) ClientCutText ¶
func (c *ClientConn) ClientCutText(text string) error
ClientCutText tells the server that the client has new text in its cut buffer. The text string MUST only contain Latin-1 characters. This encoding is compatible with Go's native string format, but can only use up to unicode.MaxLatin1 values.
func (*ClientConn) DebugMetrics ¶
func (c *ClientConn) DebugMetrics()
func (*ClientConn) DesktopName ¶
func (c *ClientConn) DesktopName() string
DesktopName returns the server provided desktop name.
func (*ClientConn) Encodings ¶
func (c *ClientConn) Encodings() Encodings
Encodings returns the server provided encodings.
func (*ClientConn) FramebufferHeight ¶
func (c *ClientConn) FramebufferHeight() uint16
FramebufferHeight returns the server provided framebuffer height.
func (*ClientConn) FramebufferUpdateRequest ¶
func (c *ClientConn) FramebufferUpdateRequest(inc uint8, x, y, w, h uint16) error
Requests a framebuffer update from the server. There may be an indefinite time between the request and the actual framebuffer update being received.
func (*ClientConn) FramebufferWidth ¶
func (c *ClientConn) FramebufferWidth() uint16
FramebufferWidth returns the server provided framebuffer width.
func (*ClientConn) KeyEvent ¶
func (c *ClientConn) KeyEvent(keysym uint32, down bool) error
KeyEvent indicates a key press or release and sends it to the server. The key is indicated using the X Window System "keysym" value. Use Google to find a reference of these values. To simulate a key press, you must send a key with both a down event, and a non-down event.
Example ¶
// Establish TCP connection. nc, err := net.DialTimeout("tcp", "127.0.0.1:5900", 10*time.Second) if err != nil { panic(fmt.Sprintf("Error connecting to host: %v\n", err)) } // Negotiate VNC connection. vc, err := Connect(context.Background(), nc, NewClientConfig("somepass")) if err != nil { panic(fmt.Sprintf("Could not negotiate a VNC connection: %v\n", err)) } // Press and release the return key. vc.KeyEvent(KeyReturn, true) vc.KeyEvent(KeyReturn, false) // Close VNC connection. vc.Close()
Output:
func (*ClientConn) ListenAndHandle ¶
func (c *ClientConn) ListenAndHandle() error
ListenAndHandle listens to a VNC server and handles server messages.
func (*ClientConn) PointerEvent ¶
func (c *ClientConn) PointerEvent(mask ButtonMask, x, y uint16) error
PointerEvent indicates that pointer movement or a pointer button press or release.
The mask is a bitwise mask of various ButtonMask values. When a button is set, it is pressed, when it is unset, it is released.
Example ¶
// Establish TCP connection. nc, err := net.DialTimeout("tcp", "127.0.0.1:5900", 10*time.Second) if err != nil { panic(fmt.Sprintf("Error connecting to host: %v\n", err)) } // Negotiate VNC connection. vc, err := Connect(context.Background(), nc, NewClientConfig("somepass")) if err != nil { panic(fmt.Sprintf("Could not negotiate a VNC connection: %v\n", err)) } // Move mouse to x=100, y=200. x, y := uint16(100), uint16(200) vc.PointerEvent(ButtonNone, x, y) // Click and release the left mouse button. vc.PointerEvent(ButtonLeft, x, y) vc.PointerEvent(ButtonNone, x, y) // Close connection. vc.Close()
Output:
func (*ClientConn) SetDebug ¶
func (c *ClientConn) SetDebug(debug bool)
SetDebugging [dis-]enables debugging.
func (*ClientConn) SetEncodings ¶
func (c *ClientConn) SetEncodings(encs Encodings) error
SetEncodings sets the encoding types in which the pixel data can be sent from the server. After calling this method, the encs slice given should not be modified.
func (*ClientConn) SetPixelFormat ¶
func (c *ClientConn) SetPixelFormat(pf PixelFormat) error
SetPixelFormat sets the format in which pixel values should be sent in FramebufferUpdate messages from the server.
type ClientCutTextMessage ¶
type ClientCutTextMessage struct { Msg uint8 // message-type Length uint32 // length // contains filtered or unexported fields }
ClientCutTextMessage holds the wire format message, sans the text field.
type Color ¶
type Color struct {
R, G, B uint16
// contains filtered or unexported fields
}
Color represents a single color in a color map.
func NewColor ¶
func NewColor(pf *PixelFormat, cm *ColorMap) *Color
type DesktopSizePseudoEncoding ¶
type DesktopSizePseudoEncoding struct{}
DesktopSizePseudoEncoding enables desktop resize support. See RFC 6143 §7.8.2.
func (*DesktopSizePseudoEncoding) Marshal ¶
func (e *DesktopSizePseudoEncoding) Marshal() ([]byte, error)
func (*DesktopSizePseudoEncoding) Read ¶
func (*DesktopSizePseudoEncoding) Read(c *ClientConn, rect *Rectangle) (Encoding, []byte, error)
func (*DesktopSizePseudoEncoding) Type ¶
func (*DesktopSizePseudoEncoding) Type() int32
type EncodableFunc ¶
type Encoding ¶
type Encoding interface { // The number that uniquely identifies this encoding type. Type() int32 // Read the contents of the encoded pixel data from the reader. // This should return a new Encoding implementation that contains // the proper data. Read(*ClientConn, *Rectangle) (Encoding, []byte, error) // Marshal implements the Marshaler interface. Marshal() ([]byte, error) }
An Encoding implements a method for encoding pixel data that is sent by the server to the client.
type FramebufferUpdate ¶
type FramebufferUpdate struct { NumRect uint16 // number-of-rectangles Rects []Rectangle // rectangles }
FramebufferUpdate holds the wire format message.
func NewFramebufferUpdate ¶
func NewFramebufferUpdate(rects []Rectangle) *FramebufferUpdate
func (*FramebufferUpdate) Marshal ¶
func (m *FramebufferUpdate) Marshal() ([]byte, error)
func (*FramebufferUpdate) Read ¶
func (m *FramebufferUpdate) Read(c *ClientConn) (ServerMessage, error)
func (*FramebufferUpdate) Type ¶
func (m *FramebufferUpdate) Type() uint8
type FramebufferUpdateRequestMessage ¶
type FramebufferUpdateRequestMessage struct { Msg uint8 // message-type Inc uint8 // incremental X, Y uint16 // x-, y-position Width, Height uint16 // width, height }
FramebufferUpdateRequestMessage holds the wire format message.
type KeyEventMessage ¶
type KeyEventMessage struct { Msg uint8 // message-type DownFlag uint8 // down-flag Key uint32 // key // contains filtered or unexported fields }
KeyEventMessage holds the wire format message.
type PixelFormat ¶
type PixelFormat struct { BPP uint8 // bits-per-pixel Depth uint8 // depth BigEndian uint8 // big-endian-flag TrueColor uint8 // true-color-flag RedMax, GreenMax, BlueMax uint16 // red-, green-, blue-max (2^BPP-1) RedShift, GreenShift, BlueShift uint8 // red-, green-, blue-shift // contains filtered or unexported fields }
PixelFormat describes the way a pixel is formatted for a VNC connection.
var ( PixelFormat8bit PixelFormat = NewPixelFormat(8) PixelFormat16bit PixelFormat = NewPixelFormat(16) PixelFormat32bit PixelFormat = NewPixelFormat(32) )
func NewPixelFormat ¶
func NewPixelFormat(bpp uint8) PixelFormat
NewPixelFormat returns a populated PixelFormat structure.
func (PixelFormat) Len ¶
func (pf PixelFormat) Len() int
Len returns the length of a PixelFormat struct.
func (PixelFormat) Marshal ¶
func (pf PixelFormat) Marshal() ([]byte, error)
Marshal implements the Marshaler interface.
func (*PixelFormat) Read ¶
func (pf *PixelFormat) Read(r io.Reader) error
Read reads from an io.Reader, and populates the PixelFormat.
func (*PixelFormat) Unmarshal ¶
func (pf *PixelFormat) Unmarshal(data []byte) error
Unmarshal implements the Unmarshaler interface.
type PointerEventMessage ¶
type PointerEventMessage struct { Msg uint8 // message-type Mask uint8 // button-mask X, Y uint16 // x-, y-position }
PointerEventMessage holds the wire format message.
type RawEncoding ¶
type RawEncoding struct {
Colors []Color
}
RawEncoding is raw pixel data sent by the server. See RFC 6143 §7.7.1.
func (*RawEncoding) Marshal ¶
func (e *RawEncoding) Marshal() ([]byte, error)
func (*RawEncoding) Read ¶
func (*RawEncoding) Read(c *ClientConn, rect *Rectangle) (Encoding, []byte, error)
func (*RawEncoding) Type ¶
func (*RawEncoding) Type() int32
type Rectangle ¶
type Rectangle struct {
X, Y uint16
Width, Height uint16
Enc Encoding
BytePix []byte
// contains filtered or unexported fields
}
Rectangle represents a rectangle of pixel data.
func NewRectangle ¶
func NewRectangle(c *ClientConn) *Rectangle
func (*Rectangle) DebugPrint ¶
func (r *Rectangle) DebugPrint()
func (*Rectangle) Read ¶
func (r *Rectangle) Read(c *ClientConn) error
Read a rectangle from a connection.
type ServerCutText ¶
type ServerCutText struct {
Text string
}
ServerCutText indicates the server has new text in the cut buffer.
func (*ServerCutText) Read ¶
func (*ServerCutText) Read(c *ClientConn) (ServerMessage, error)
func (*ServerCutText) Type ¶
func (*ServerCutText) Type() uint8
type ServerMessage ¶
type ServerMessage interface { // The type of the message that is sent down on the wire. Type() uint8 // Read reads the contents of the message from the reader. At the point // this is called, the message type has already been read from the reader. // This should return a new ServerMessage that is the appropriate type. Read(*ClientConn) (ServerMessage, error) }
A ServerMessage implements a message sent from the server to the client.
type SetColorMapEntries ¶
func (*SetColorMapEntries) Read ¶
func (*SetColorMapEntries) Read(c *ClientConn) (ServerMessage, error)
func (*SetColorMapEntries) Type ¶
func (*SetColorMapEntries) Type() uint8
type SetEncodingsMessage ¶
type SetEncodingsMessage struct { Msg uint8 // message-type NumEncs uint16 // number-of-encodings // contains filtered or unexported fields }
SetEncodingsMessage holds the wire format message, sans encoding-type field.
type SetPixelFormatMessage ¶
type SetPixelFormatMessage struct { Msg uint8 // message-type PF PixelFormat // pixel-format // contains filtered or unexported fields }
SetPixelFormatMessage holds the wire format message.
type Unmarshaler ¶
Unmarshaler is the interface for objects that can marshal themselves.