Class: NetworkProjector::NPClient

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

Instance Method Summary collapse

Instance Method Details

#connectObject



67
68
69
70
71
72
73
# File 'lib/network-projector/client/app.rb', line 67

def connect
		request = Net::HTTP::Post.new("/connect")
		request.set_form_data({"user" => @user, "vnc[port]" => @vs.port, "vnc[passwd]" => @vs.passwd})
		response = @http.request(request)
		@id = response.body
		puts "Connected as #{@id}"
end

#disconnectObject



75
76
77
78
79
80
# File 'lib/network-projector/client/app.rb', line 75

def disconnect
		request = Net::HTTP::Post.new("/disconnect")
		request.set_form_data({"id" => @id})
		response = @http.request(request)
		puts "Disconnect response (#{response.code}) : #{response.body}" unless response.code == "200"
end

#run!Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/network-projector/client/app.rb', line 8

def run!
	options = {:passwd=>'unsecure', :host=>'localhost', :display=>":0", :clip => "xinerama0", :user=>Socket.gethostname}

	parser = OptionParser.new

	parser.on('--help', 'displays usage information') do
		puts parser
		exit
	end

	parser.on('-h=HOST', '--host=HOST', "Projector host (#{options[:host]})") do |v|
		options[:host] = v
	end

	parser.on('-d=DISPLAY', '--display=HOST', "Local display to share (#{options[:display]})") do |v|
		options[:display] = v
	end

	parser.on('-u=USER', '--user=USER', "User label (#{options[:label]})") do |v|
		options[:user] = v
	end

	parser.on('-p=PASSWD', '--passwd=PASSWD', 'Vnc password') do |v|
		options[:passwd] = v
	end

	begin
		parser.parse($*)
	rescue OptionParser::ParseError
		puts $!
		exit
	end

	@user = options[:user]

	@vs = VncShare.new options

	@vs.run

	if not @vs.started? then
		puts "Can't start, leaving"
		return
	end
	begin
		@http = Net::HTTP.new(options[:host], 4567)
		connect
		puts "Ready for connection"
		@vs.join
	rescue SystemCallError => e
		puts "Connection to #{options[:host]}:4567 failed : #{e}"
		@vs.stop
	rescue Interrupt
		@vs.stop
	ensure
		disconnect
	end
	puts "Leaving"
end