Class: Relayer::IRCSocket
- Inherits:
-
Object
- Object
- Relayer::IRCSocket
- Defined in:
- lib/relayer/socket.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(client, host, port, ssl = false) ⇒ IRCSocket
constructor
A new instance of IRCSocket.
- #read ⇒ Object
- #send(line) ⇒ Object
Constructor Details
#initialize(client, host, port, ssl = false) ⇒ IRCSocket
Returns a new instance of IRCSocket.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/relayer/socket.rb', line 6 def initialize(client, host, port, ssl = false) @client = client @socket = TCPSocket.new(host, port) if ssl @socket = OpenSSL::SSL::SSLSocket.new(@socket) @socket.sync_close = true # close both wrapper and irc socket on close @socket.connect end IRCSocketSelector.add_irc_socket(@socket, @client) end |
Instance Method Details
#close ⇒ Object
34 35 36 |
# File 'lib/relayer/socket.rb', line 34 def close @socket.close end |
#read ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/relayer/socket.rb', line 19 def read data = @socket.gets data = data.sub "\r", '' lines = data.split "\r\n" lines.each do |line| @client.process_raw line end end |
#send(line) ⇒ Object
30 31 32 |
# File 'lib/relayer/socket.rb', line 30 def send(line) @socket.puts line end |