Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
== Unreleased

- Made helpers to read/send information from/to server

== 1.1.0 / 2012-06-03

- Fixes to support ruby 1.9 (jedi4ever & codemonkeyjohn).
Expand Down
36 changes: 32 additions & 4 deletions lib/net/vnc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,34 @@ def port
BASE_PORT + @display
end

def readU8(data)
data.unpack('C')[0]
end

def writeU8(data)
data.chr
end

def readU16(data)
data.unpack('n')[0]
end

def writeU16(data)
[data].pack('n')
end

def readU32(data)
data.unpack('N')[0]
end

def writeU32(data)
[data].pack('N')
end

def readS32(data)
data.unpack('l')[0]
end

def connect
@socket = TCPSocket.open server, port
unless socket.read(12) =~ /^RFB (\d{3}.\d{3})\n$/
Expand All @@ -128,7 +156,7 @@ def connect
end

# ClientInitialisation
socket.write((options[:shared] ? 1 : 0).chr)
socket.write(writeU8(options[:shared] ? 1 : 0))

# ServerInitialisation
# TODO: parse this.
Expand Down Expand Up @@ -279,8 +307,8 @@ def read_packet type
case type
when 3 # ServerCutText
socket.read 3 # discard padding bytes
len = socket.read(4).unpack('N')[0]
@mutex.synchronize { @clipboard = socket.read len }
len = readU32(socket.read(4))
@mutex.synchronize { @clipboard = socket.read(len) }
else
raise NotImplementedError, 'unhandled server packet type - %d' % type
end
Expand All @@ -292,7 +320,7 @@ def packet_reading_thread
begin
break if @packet_reading_state != :loop
next unless IO.select [socket], nil, nil, 2
type = socket.read(1)[0]
type = readU8(socket.read(1))
read_packet type
rescue
warn "exception in packet_reading_thread: #{$!.class}:#{$!}"
Expand Down