Class: JsonRpcTcpServer
- Inherits:
-
JsonRpcServer
- Object
- JsonRpcServer
- JsonRpcTcpServer
- Defined in:
- lib/jsonrpc2.0-tcp/Server.rb
Instance Method Summary collapse
-
#initialize(port, opts = {}) ⇒ JsonRpcTcpServer
constructor
A new instance of JsonRpcTcpServer.
- #login ⇒ Object
- #run ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(port, opts = {}) ⇒ JsonRpcTcpServer
Returns a new instance of JsonRpcTcpServer.
6 7 8 9 10 11 12 13 |
# File 'lib/jsonrpc2.0-tcp/Server.rb', line 6 def initialize(port, opts = {}) @loginMethod = opts['loginMethod'] @shutdownTimeout = opts['shutdownTimeout'] @server = TCPServer.new('localhost', port) @runLoop = nil @connections = nil end |
Instance Method Details
#login ⇒ Object
47 48 49 |
# File 'lib/jsonrpc2.0-tcp/Server.rb', line 47 def login Thread.current.login end |
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/jsonrpc2.0-tcp/Server.rb', line 15 def run() if @runLoop == nil @connections = ThreadGroup.new @runLoop = Thread.start do loop do thr = ConnectionThread.start(@server.accept) do |conn| selfThread = Thread.current selfThread.loginMethod = @loginMethod while @runLoop != nil and ( = conn.gets) != nil selfThread.stop_timeout conn.puts (, selfThread.restrict) end conn.close end @connections.add thr end end @runLoop.join @runLoop = nil @connections.list.each do |conn| conn.join end @connections = nil end end |
#stop ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/jsonrpc2.0-tcp/Server.rb', line 51 def stop @runLoop.exit @runLoop = nil unless @shutdownTimeout == nil @connections.list.each do |conn| conn.start_timeout(@shutdownTimeout) end end end |