Class: Rakie::TCPChannel

Inherits:
Channel show all
Defined in:
lib/rakie/tcp_channel.rb

Direct Known Subclasses

TCPServerChannel

Constant Summary collapse

LOCAL_HOST =
'127.0.0.1'

Constants inherited from Channel

Channel::DEFAULT_BUFFER_SIZE

Instance Attribute Summary

Attributes inherited from Channel

#delegate

Instance Method Summary collapse

Methods inherited from Channel

#close, #closed?, #eof?, #handle_write, #on_detach, #on_read, #on_write, #read, #write

Constructor Details

#initialize(host, port, delegate) ⇒ TCPChannel #initialize(host, port) ⇒ TCPChannel #initialize(host, port, delegate, socket) ⇒ TCPChannel

Returns a new instance of TCPChannel.

Parameters:

  • host (String) (defaults to: LOCAL_HOST)
  • port (Integer) (defaults to: 3001)
  • delegate (Object) (defaults to: nil)
  • socket (Socket) (defaults to: nil)


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rakie/tcp_channel.rb', line 12

def initialize(host=LOCAL_HOST, port=3001, delegate=nil, socket=nil)
  if socket == nil
    socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM)
    socket.connect(Socket.pack_sockaddr_in(port, host))
  end

  @port = port
  @host = host

  super(socket, delegate)
end