Class: Mumble::Connection
- Inherits:
-
Object
- Object
- Mumble::Connection
- Defined in:
- lib/mumble-ruby/connection.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect ⇒ Object
-
#initialize(host, port) ⇒ Connection
constructor
A new instance of Connection.
- #read_message ⇒ Object
- #send_message(sym, attrs) ⇒ Object
- #send_udp_packet(packet) ⇒ Object
Constructor Details
#initialize(host, port) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 |
# File 'lib/mumble-ruby/connection.rb', line 7 def initialize(host, port) @host = host @port = port @write_lock = Mutex.new end |
Instance Method Details
#connect ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/mumble-ruby/connection.rb', line 13 def connect context = OpenSSL::SSL::SSLContext.new context.verify_mode = OpenSSL::SSL::VERIFY_NONE tcp_sock = TCPSocket.new @host, @port @sock = OpenSSL::SSL::SSLSocket.new tcp_sock, context @sock.connect end |
#disconnect ⇒ Object
21 22 23 |
# File 'lib/mumble-ruby/connection.rb', line 21 def disconnect @sock.sysclose end |
#read_message ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mumble-ruby/connection.rb', line 25 def header = read_data 6 type, len = header.unpack Messages::HEADER_FORMAT data = read_data len if type == (:udp_tunnel) # UDP Packet -- No Protobuf = (:udp_tunnel).new .packet = data else = type, data end end |
#send_message(sym, attrs) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/mumble-ruby/connection.rb', line 44 def (sym, attrs) type, klass = (sym) = klass.new attrs.each { |k, v| .send("#{k}=", v) } serial = .serialize_to_string header = [type, serial.size].pack Messages::HEADER_FORMAT send_data(header + serial) end |
#send_udp_packet(packet) ⇒ Object
39 40 41 42 |
# File 'lib/mumble-ruby/connection.rb', line 39 def send_udp_packet(packet) header = [(:udp_tunnel), packet.length].pack Messages::HEADER_FORMAT send_data(header + packet) end |