Class: Nova::Starbound::Client
- Inherits:
-
Object
- Object
- Nova::Starbound::Client
- Defined in:
- lib/nova/starbound/client.rb
Overview
A client for Nova.
Constant Summary collapse
- DEFAULT_OPTIONS =
The default options when dealing with this class.
{ :type => :tcp, :host => "127.0.0.1", :port => 2010 }
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
The options that were passed to the client on initialization.
-
#protocol ⇒ Protocol
readonly
The underlying protocol that powers this client.
Instance Method Summary collapse
-
#handshake ⇒ void
Do the handshake with the server.
-
#initialize(options = {}) ⇒ Client
constructor
Initialize with the given options.
-
#socket ⇒ Object
Create the socket.
Constructor Details
#initialize(options = {}) ⇒ Client
Initialize with the given options.
29 30 31 32 33 |
# File 'lib/nova/starbound/client.rb', line 29 def initialize( = {}) = DEFAULT_OPTIONS.merge() = (.delete(:protocol) || {}).dup @protocol = Protocol.new .merge(:type => :client) end |
Instance Attribute Details
#options ⇒ Hash (readonly)
The options that were passed to the client on initialization.
12 13 14 |
# File 'lib/nova/starbound/client.rb', line 12 def end |
#protocol ⇒ Protocol (readonly)
The underlying protocol that powers this client.
17 18 19 |
# File 'lib/nova/starbound/client.rb', line 17 def protocol @protocol end |
Instance Method Details
#handshake ⇒ void
This method returns an undefined value.
Do the handshake with the server.
38 39 40 41 |
# File 'lib/nova/starbound/client.rb', line 38 def handshake @protocol.socket = socket @protocol.handshake end |
#socket ⇒ Object
Create the socket.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/nova/starbound/client.rb', line 46 def socket @_socket ||= case [:type] when :tcp TCPSocket.new([:host], [:port]) when :unix UNIXSocket.new([:path]) when :pipe [:pipe] end end |