Class: VlSync::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/VlSync/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



4
5
6
7
8
9
10
# File 'lib/VlSync/client.rb', line 4

def initialize
  @args = ['--extraintf', 'rc', '--rc-host', "#{VlSync.opts[:hostname]}:#{VlSync.opts[:port]}"]
  puts "Client started at #{VlSync.opts[:hostname]} on port #{VlSync.opts[:port]}"
  @vlc = VlSync.vlc
  @pid = Process.spawn @vlc, *@args
  listener
end

Instance Method Details

#listenerObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/VlSync/client.rb', line 12

def listener
  BasicSocket.do_not_reverse_lookup = true
  addr = [VlSync.opts[:bind], VlSync.opts[:port]+1]
  puts "Starting multicast at bind: #{addr[0]} on port #{addr[1]}"
  s = UDPSocket.new
  s.bind(addr[0], addr[1])
  loop do
    message, addr = s.recvfrom(255)
    if message =~ /DISCOVER_VLSYNC/
      sock = UDPSocket.new(addr[0])
      puts "Host Found: #{addr[2]}"
      sock.send("PONG_VLSYNC", 0, addr[2], VlSync.opts[:port])
    end
  end
end