Class: Net::TOC::Connection
- Inherits:
-
Object
- Object
- Net::TOC::Connection
- Includes:
- Net::TOC
- Defined in:
- lib/aim/net_toc.rb
Overview
The Connection class handles low-level communication using the TOC protocol. You shouldn’t use it directly.
Constant Summary collapse
- FrameType =
{ :sign_on => 1, :data => 2 }
Constants included from Net::TOC
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(screen_name) ⇒ Connection
constructor
A new instance of Connection.
- #open(server = "toc.oscar.aol.com", port = 9898) ⇒ Object
- #recv ⇒ Object
- #send(message, type = :data) ⇒ Object
Methods included from Net::TOC
#format_message, #format_screen_name, new
Constructor Details
#initialize(screen_name) ⇒ Connection
Returns a new instance of Connection.
183 184 185 186 |
# File 'lib/aim/net_toc.rb', line 183 def initialize(screen_name) @user = format_screen_name screen_name @msgseq = rand(100000) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(command, *args) ⇒ Object (private)
Any unknown methods are assumed to be messages for the server.
238 239 240 241 |
# File 'lib/aim/net_toc.rb', line 238 def method_missing(command, *args) puts ([command] + args).join(" ").inspect send(([command] + args).join(" ")) end |
Instance Method Details
#close ⇒ Object
199 200 201 |
# File 'lib/aim/net_toc.rb', line 199 def close @sock.close unless @sock.nil? end |
#open(server = "toc.oscar.aol.com", port = 9898) ⇒ Object
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/aim/net_toc.rb', line 188 def open(server="toc.oscar.aol.com", port=9898) close @sock = TCPSocket.new(server, port) @sock.send "FLAPON\r\n\r\n", 0 toc_version = *recv.unpack("N") send [1, 1, @user.length, @user].pack("Nnna*"), :sign_on end |
#recv ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/aim/net_toc.rb', line 217 def recv header = @sock.recv 6 raise CommunicationError, "Server didn't send full header." if header.length < 6 asterisk, type, serverseq, length = header.unpack "aCnn" response = @sock.recv length puts " recv: #{response}" if Debug unless type == FrameType[:sign_on] , value = response.split(":", 2) unless .nil? or value.nil? msg_sym = .downcase.to_sym yield msg_sym, value if block_given? end end response end |
#send(message, type = :data) ⇒ Object
208 209 210 211 212 213 214 215 |
# File 'lib/aim/net_toc.rb', line 208 def send(, type=:data) << "\0" puts " send: #{message}" if Debug @msgseq = @msgseq.next header = ['*', FrameType[type], @msgseq, .length].pack("aCnn") packet = header + @sock.send packet, 0 end |