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
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#remote_addr ⇒ Object
readonly
Returns the value of attribute remote_addr.
-
#remote_host ⇒ Object
readonly
Returns the value of attribute remote_host.
-
#remote_port ⇒ Object
readonly
Returns the value of attribute remote_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) @message = @sockaddr = sockaddr @remote_port = sockaddr[1] @remote_host = sockaddr[2] @remote_addr = sockaddr[3] end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
8 9 10 |
# File 'lib/socketry/udp/datagram.rb', line 8 def @message end |
#remote_addr ⇒ Object (readonly)
Returns the value of attribute remote_addr.
8 9 10 |
# File 'lib/socketry/udp/datagram.rb', line 8 def remote_addr @remote_addr end |
#remote_host ⇒ Object (readonly)
Returns the value of attribute remote_host.
8 9 10 |
# File 'lib/socketry/udp/datagram.rb', line 8 def remote_host @remote_host end |
#remote_port ⇒ Object (readonly)
Returns the value of attribute remote_port.
8 9 10 |
# File 'lib/socketry/udp/datagram.rb', line 8 def remote_port @remote_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 |