echo_server.rb in zmachine-0.1.3 vs echo_server.rb in zmachine-0.2.0

- old
+ new

@@ -1,41 +1,34 @@ #!/usr/bin/env ruby require 'rubygems' require 'bundler/setup' +require 'madvertise/boot' require 'zmachine' -java_import org.zeromq.ZMQ -java_import org.zeromq.ZFrame +$log.level = :debug +ZMachine.logger = $log +ZMachine.debug = true #set_trace_func proc { |event, file, line, id, binding, classname| # printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname #} -class EchoServer < ZMachine::Connection - def receive_data(msg) - origin = msg.unwrap - puts "recv(#{msg.to_a.map {|f| String.from_java_bytes(f.data) }.inspect})" - msg = ZMsg.new_string_msg("ok") - msg.wrap(origin) - send_data(msg) +class ZMQEchoServer < ZMachine::Connection + def receive_data(buffer) + send_data(buffer) end end +class TCPEchoServer < ZMachine::Connection + def receive_data(buffer) + send_data(buffer) + end +end + ZMachine.run do - ZMachine.start_server("tcp://*:10000", ZMQ::ROUTER, EchoServer) do |handler| + ZMachine.start_server("tcp://*:10000", ZMQ::ROUTER, ZMQEchoServer) do |handler| handler.channel.identity = "server" end - #ZMachine.start_server("0.0.0.0", 10000, EchoServer) + #ZMachine.start_server("0.0.0.0", 10000, TCPEchoServer) puts "machine running" end - -#ctx = ZContext.new -#socket = ctx.create_socket(ZMQ::ROUTER) -#socket.bind("tcp://127.0.0.1:10000") -#socket.identity = "server".to_java_bytes - -#loop do -# puts socket.events.inspect -# msg = ZMsg.recvMsg(socket) -# puts "recv(#{msg.to_a.map {|f| String.from_java_bytes(f.data) }.inspect})" -#end