File: pingpong.rb

package info (click to toggle)
ruby-faye 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,792 kB
  • sloc: javascript: 14,833; ruby: 5,068; makefile: 30
file content (22 lines) | stat: -rw-r--r-- 474 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
require 'rubygems'
require 'bundler/setup'
require 'faye'

EM.run {
  ENDPOINT = 'http://0.0.0.0:9292/bayeux'
  puts 'Connecting to ' + ENDPOINT

  ping = Faye::Client.new(ENDPOINT)
  ping.subscribe('/ping') do
    puts 'PING'
    EM.add_timer(1) { ping.publish('/pong', {}) }
  end

  pong = Faye::Client.new(ENDPOINT)
  pong.subscribe('/pong') do
    puts 'PONG'
    EM.add_timer(1) { ping.publish('/ping', {}) }
  end

  EM.add_timer(0.5) { ping.publish('/pong', {}) }
}