Class: OSC::SimpleServer

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

Instance Method Summary collapse

Constructor Details

#initialize(port) ⇒ SimpleServer

Returns a new instance of SimpleServer.



276
277
278
279
280
281
# File 'lib/osc.rb', line 276

def initialize(port)
  @so = UDPSocket.new
  @so.bind('', port)
  @cb = []
  @qu = Queue.new
end

Instance Method Details

#add_method(pat, obj = nil, &proc) ⇒ Object



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/osc.rb', line 283

def add_method(pat, obj=nil, &proc)
  case pat
  when NIL; re = pat
  when Regexp; re = pat
  when String
  pat = pat.dup
  pat.gsub!(/[.^(|)]/, '\\1')
  pat.gsub!(/\?/, '[^/]')
  pat.gsub!(/\*/, '[^/]*')
  pat.gsub!(/\[!/, '[^')
  pat.gsub!(/\{/, '(')
  pat.gsub!(/,/, '|')
  pat.gsub!(/\}/, ')')
  pat.gsub!(/\A/, '\A')
  pat.gsub!(/\z/, '\z')
  re = Regexp.new(pat)
  else
  raise ArgumentError, 'invalid pattern'
  end
  unless ( obj && !proc) ||
  (!obj &&  proc)
  raise ArgumentError, 'wrong number of arguments'
  end
  @cb << [re, (obj || proc)]
end

#runObject



347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/osc.rb', line 347

def run
  Thread.fork do
  begin
    dispatcher
  rescue
    Thread.main.raise $!
  end
  end
  begin
  detector
  rescue
  Thread.main.raise $!
  end
end