Class: Socketry::UDP::Datagram

Inherits:
Object
  • Object
show all
Defined in:
lib/socketry/udp/datagram.rb

Overview

Represents a received UDP message

Instance Attribute Summary collapse

Instance Method Summary collapse

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(message, sockaddr)
  @message  = message
  @sockaddr = sockaddr
  @port     = sockaddr[1]
  @host     = sockaddr[2]
  @addr     = sockaddr[3]
end

Instance Attribute Details

#addrObject (readonly)

Returns the value of attribute addr.



8
9
10
# File 'lib/socketry/udp/datagram.rb', line 8

def addr
  @addr
end

#hostObject (readonly)

Returns the value of attribute host.



8
9
10
# File 'lib/socketry/udp/datagram.rb', line 8

def host
  @host
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/socketry/udp/datagram.rb', line 8

def message
  @message
end

#portObject (readonly)

Returns the value of attribute port.



8
9
10
# File 'lib/socketry/udp/datagram.rb', line 8

def port
  @port
end

#sockaddrObject (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

#addrinfoObject



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