Module: TCPMessenger

Defined in:
lib/tcp_messenger.rb,
lib/tcp_messenger/server.rb,
lib/tcp_messenger/messenger.rb,
lib/tcp_messenger/closed_error.rb,
lib/tcp_messenger/connection_error.rb,
lib/tcp_messenger/message_too_long_error.rb

Defined Under Namespace

Classes: ClosedError, ConnectionError, MessageTooLongError, Messenger, Server

Class Method Summary collapse

Class Method Details

.accept(duck_types: {}, max_message_length: Float::INFINITY, port:) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/tcp_messenger.rb', line 23

def self.accept(duck_types: {}, max_message_length: Float::INFINITY, port: )
  tcp_server_class = duck_types[:tcp_server] || TCPServer
  server = Server.new(tcp_server_class.new(port), duck_types: duck_types, max_message_length: max_message_length)
  socket = server.accept
  server.close
  socket
end

.connect(duck_types: {}, host:, max_message_length: Float::INFINITY, port:) ⇒ Object



12
13
14
15
16
# File 'lib/tcp_messenger.rb', line 12

def self.connect(duck_types: {}, host: , max_message_length: Float::INFINITY, port: )
  tcp_socket_class = duck_types[:tcp_socket] || TCPSocket
  socket = tcp_socket_class.new(host, port)
  Messenger.new(socket, duck_types: duck_types, max_message_length: max_message_length)
end

.listen(duck_types: {}, max_message_length: Float::INFINITY, port:) ⇒ Object



18
19
20
21
# File 'lib/tcp_messenger.rb', line 18

def self.listen(duck_types: {}, max_message_length: Float::INFINITY, port: )
  tcp_server_class = duck_types[:tcp_server] || TCPServer
  Server.new(tcp_server_class.new(port), duck_types: duck_types, max_message_length: max_message_length)
end