Sha256: 1fc19b356dba9d061a140900f8b2804a02d80d0d1b9c076ef6f06e93441cdf9e
Contents?: true
Size: 1.45 KB
Versions: 4
Compression:
Stored size: 1.45 KB
Contents
class MyServer @port = 65500 attr_accessor :port def initialize(svr) @svr = svr @count = 0 end def hello "ok" end def sum(a, b) a + b end def count @count end def increase_count @count += 1 end def exception raise "raised" end def async as = MessagePack::RPC::AsyncResult.new @svr.start_timer(1, false) do as.result "async" end as end def async_exception as = MessagePack::RPC::AsyncResult.new @svr.start_timer(1, false) do as.error "async" end as end def self.port @port end private def hidden end end module MyServerTest def start_client(port) cli = MessagePack::RPC::Client.new("127.0.0.1", port) cli.timeout = 10 return cli end def start_server port = PortHelper.find_port svr = MessagePack::RPC::Server.new svr.listen("0.0.0.0", port, MyServer.new(svr)) Thread.start do svr.run svr.close end return svr, start_client(port) end def server_start_loop port = PortHelper.find_port loop = MessagePack::RPC::Loop.new svr =MessagePack::RPC::Server.new(loop) svr.listen("0.0.0.0", port ,MyServer.new(svr)) cli = MessagePack::RPC::Client.new("127.0.0.1", port, loop) cli.timeout = 10 return svr,cli end end module PortHelper def self.find_port s = TCPServer.new('127.0.0.1', 0) port = s.addr[1] port ensure s.close end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
msgpack-rpc-0.7.0 | spec/unit/my_server.rb |
msgpack-rpc-0.6.0 | spec/unit/my_server.rb |
msgpack-rpc-0.5.4 | spec/unit/my_server.rb |
msgpack-rpc-0.5.3 | spec/unit/my_server.rb |