Class: VncClient

Inherits:
Object
  • Object
show all
Defined in:
lib/network-projector/vnc/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



7
8
9
# File 'lib/network-projector/vnc/client.rb', line 7

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



7
8
9
# File 'lib/network-projector/vnc/client.rb', line 7

def port
  @port
end

Instance Method Details

#joinObject



37
38
39
40
41
# File 'lib/network-projector/vnc/client.rb', line 37

def join
	@passwdfile.unlink if @passwdfile
	@thread.join if @thread
	@thread = nil
end

#run(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/network-projector/vnc/client.rb', line 9

def run options = {}
	@host   = (options[:host])
	@port   = (options[:port])
	@passwd = (options[:passwd])

	raise "need a host to contact" unless @host
	raise "need a port to contact" unless @port

	@passwdfile = Tempfile.new("vnc")
	`echo #{@passwd.shellescape} | vncpasswd -f > #{@passwdfile.path}`
	pin, pout, @thread = Open3.popen2e("vncviewer -passwd #{@passwdfile.path} #{@host.shellescape}:#{@port.shellescape} -fullscreen") 
end

#started?Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/network-projector/vnc/client.rb', line 22

def started?
	join unless (@thread.nil? or @thread.alive?)
	@thread.nil? == false
end

#stopObject



27
28
29
30
31
32
33
34
35
# File 'lib/network-projector/vnc/client.rb', line 27

def stop
	if @thread then	
		begin
			Process.kill("TERM", @thread.pid)
		rescue Errno::ESRCH
		end
	end
	join	
end