25. a chat service
chat server
hi!
kenneth hi!
sean hi!
mark
26. a chat service
# create the context server.rb
context = ZMQ::Context.new(1)
# create the two sockets we need
pub = context.socket(ZMQ::PUB)
pull = context.socket(ZMQ::PULL)
# bind the sockets
pub.bind('tcp://*:1338')
pull.bind('tcp://*:1337')
# wait for input, and forward to all subscribers
while body = pull.recv
payload = JSON.parse(body)
pub.send "#{payload['user']}> #{payload['message'].cyan}"
end
27. a chat service
# create the context server.rb
context = ZMQ::Context.new(1)
# create the two sockets we need
pub = context.socket(ZMQ::PUB)
pull = context.socket(ZMQ::PULL)
# bind the sockets
pub.bind('tcp://*:1338')
pull.bind('tcp://*:1337')
# wait for input, and forward to all subscribers
while body = pull.recv
payload = JSON.parse(body)
pub.send "#{payload['user']}> #{payload['message'].cyan}"
end
28. a chat service
# create the context server.rb
context = ZMQ::Context.new(1)
# create the two sockets we need
pub = context.socket(ZMQ::PUB)
pull = context.socket(ZMQ::PULL)
# bind the sockets
pub.bind('tcp://*:1338')
pull.bind('tcp://*:1337')
# wait for input, and forward to all subscribers
while body = pull.recv
payload = JSON.parse(body)
pub.send "#{payload['user']}> #{payload['message'].cyan}"
end
29. a chat service
# create the context server.rb
context = ZMQ::Context.new(1)
# create the two sockets we need
pub = context.socket(ZMQ::PUB)
pull = context.socket(ZMQ::PULL)
# bind the sockets
pub.bind('tcp://*:1338')
pull.bind('tcp://*:1337')
# wait for input, and forward to all subscribers
while body = pull.recv
payload = JSON.parse(body)
pub.send "#{payload['user']}> #{payload['message'].cyan}"
end
30. a chat service
# create the context server.rb
context = ZMQ::Context.new(1)
# create the two sockets we need
pub = context.socket(ZMQ::PUB)
pull = context.socket(ZMQ::PULL)
# bind the sockets
pub.bind('tcp://*:1338')
pull.bind('tcp://*:1337')
# wait for input, and forward to all subscribers
while body = pull.recv
payload = JSON.parse(body)
pub.send "#{payload['user']}> #{payload['message'].cyan}"
end
31. a chat service
# create the context client.rb
context = ZMQ::Context.new(1)
# create the two sockets we need
sub = context.socket(ZMQ::SUB)
sub.setsockopt(ZMQ::SUBSCRIBE, '')
push = context.socket(ZMQ::PUSH)
# bind the sockets
sub.connect("tcp://#{server}:1338")
push.connect("tcp://#{server}:1337")
# wait for some input
while line = gets.chomp
push.send(line) unless line == ''
# dump buffered messages
puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK))
end
32. a chat service
# create the context client.rb
context = ZMQ::Context.new(1)
# create the two sockets we need
sub = context.socket(ZMQ::SUB)
sub.setsockopt(ZMQ::SUBSCRIBE, '')
push = context.socket(ZMQ::PUSH)
# bind the sockets
sub.connect("tcp://#{server}:1338")
push.connect("tcp://#{server}:1337")
# wait for some input
while line = gets.chomp
push.send(line) unless line == ''
# dump buffered messages
puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK))
end
33. a chat service
# create the context client.rb
context = ZMQ::Context.new(1)
# create the two sockets we need
sub = context.socket(ZMQ::SUB)
sub.setsockopt(ZMQ::SUBSCRIBE, '')
push = context.socket(ZMQ::PUSH)
# bind the sockets
sub.connect("tcp://#{server}:1338")
push.connect("tcp://#{server}:1337")
# wait for some input
while line = gets.chomp
push.send(line) unless line == ''
# dump buffered messages
puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK))
end
34. a chat service
# create the context client.rb
context = ZMQ::Context.new(1)
# create the two sockets we need
sub = context.socket(ZMQ::SUB)
sub.setsockopt(ZMQ::SUBSCRIBE, '')
push = context.socket(ZMQ::PUSH)
# bind the sockets
sub.connect("tcp://#{server}:1338")
push.connect("tcp://#{server}:1337")
# wait for some input
while line = gets.chomp
push.send(line) unless line == ''
# dump buffered messages
puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK))
end
35. a chat service
# create the context client.rb
context = ZMQ::Context.new(1)
# create the two sockets we need
sub = context.socket(ZMQ::SUB)
sub.setsockopt(ZMQ::SUBSCRIBE, '')
push = context.socket(ZMQ::PUSH)
# bind the sockets
sub.connect("tcp://#{server}:1338")
push.connect("tcp://#{server}:1337")
# wait for some input
while line = gets.chomp
push.send(line) unless line == ''
# dump buffered messages
puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK))
end
36. a chat service
# create the context client.rb
context = ZMQ::Context.new(1)
# create the two sockets we need
sub = context.socket(ZMQ::SUB)
sub.setsockopt(ZMQ::SUBSCRIBE, '')
push = context.socket(ZMQ::PUSH)
# bind the sockets
sub.connect("tcp://#{server}:1338")
push.connect("tcp://#{server}:1337")
# wait for some input
while line = gets.chomp
push.send(line) unless line == ''
# dump buffered messages
puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK))
end
37. a chat service
# create the context client.rb
context = ZMQ::Context.new(1)
# create the two sockets we need
sub = context.socket(ZMQ::SUB)
sub.setsockopt(ZMQ::SUBSCRIBE, '')
push = context.socket(ZMQ::PUSH)
# bind the sockets
sub.connect("tcp://#{server}:1338")
push.connect("tcp://#{server}:1337")
# wait for some input
while line = gets.chomp
push.send(line) unless line == ''
# dump buffered messages
puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK))
end