Class: Networking::TCPServer
- Inherits:
-
Object
- Object
- Networking::TCPServer
- Defined in:
- lib/networking/tcp.rb
Overview
Limit on number of concurrent connections? The TCP server is not responsible for reconnection.
Instance Attribute Summary collapse
-
#tcp_thread ⇒ Object
readonly
Returns the value of attribute tcp_thread.
Instance Method Summary collapse
-
#initialize(port, obj_clb, new_clb = nil, closed_clb = nil, max_parallel = 1) ⇒ TCPServer
constructor
A new instance of TCPServer.
- #send_obj(obj, addr_info = nil) ⇒ Object
Constructor Details
#initialize(port, obj_clb, new_clb = nil, closed_clb = nil, max_parallel = 1) ⇒ TCPServer
Returns a new instance of TCPServer.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/networking/tcp.rb', line 61 def initialize(port, obj_clb, new_clb=nil, closed_clb=nil, max_parallel=1) @port = port @obj_clb = obj_clb @new_clb = new_clb @closed_clb = closed_clb # Max parallel connections is not implemented yet. @max_parallel = max_parallel @sockets = {} @tcp_thread = run_server @tcp_thread.abort_on_exception = true end |
Instance Attribute Details
#tcp_thread ⇒ Object (readonly)
Returns the value of attribute tcp_thread.
59 60 61 |
# File 'lib/networking/tcp.rb', line 59 def tcp_thread @tcp_thread end |
Instance Method Details
#send_obj(obj, addr_info = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/networking/tcp.rb', line 73 def send_obj(obj, addr_info=nil) Log.debug3("send_obj with addr_info:%s", addr_info) unless addr_info.nil? if @sockets.key?(addr_info) Networking.write_to_stream(@sockets[addr_info], obj) else Log.warning("Could not find client socket: #{addr_info}") return 0 end else out = {} @sockets.each { |key, sock| out[key] = Networking.write_to_stream(sock, obj) } return out end end |