Class: Socketry::UDP::Datagram
- Inherits:
-
Object
- Object
- Socketry::UDP::Datagram
- Defined in:
- lib/socketry/udp/datagram.rb
Overview
Represents a received UDP message
Instance Attribute Summary collapse
-
#addr ⇒ Object
readonly
Returns the value of attribute addr.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#sockaddr ⇒ Object
readonly
Returns the value of attribute sockaddr.
Instance Method Summary collapse
- #addrinfo ⇒ Object
-
#initialize(message, sockaddr) ⇒ Datagram
constructor
A new instance of Datagram.
Constructor Details
#initialize(message, sockaddr) ⇒ Datagram
Returns a new instance of Datagram.
10 11 12 13 14 15 16 |
# File 'lib/socketry/udp/datagram.rb', line 10 def initialize(, sockaddr) = @sockaddr = sockaddr @port = sockaddr[1] @host = sockaddr[2] @addr = sockaddr[3] end |
Instance Attribute Details
#addr ⇒ Object (readonly)
Returns the value of attribute addr.
8 9 10 |
# File 'lib/socketry/udp/datagram.rb', line 8 def addr @addr end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'lib/socketry/udp/datagram.rb', line 8 def host @host end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
8 9 10 |
# File 'lib/socketry/udp/datagram.rb', line 8 def end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/socketry/udp/datagram.rb', line 8 def port @port end |
#sockaddr ⇒ Object (readonly)
Returns the value of attribute sockaddr.
8 9 10 |
# File 'lib/socketry/udp/datagram.rb', line 8 def sockaddr @sockaddr end |
Instance Method Details
#addrinfo ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/socketry/udp/datagram.rb', line 18 def addrinfo addr_family = case @sockaddr[0] when "AF_INET" then ::Socket::AF_INET when "AF_INET6" then ::Socket::AF_INET6 else raise Socketry::AddressError, "unsupported IP address family: #{@sockaddr[0]}" end Addrinfo.new(@sockaddr, addr_family, ::Socket::SOCK_DGRAM) end |