class SFML::Network::IpAddress
An IPv4 address. The CSFML side stores it as a fixed-size 16-byte NUL-terminated dotted-decimal string (“192.168.1.42”).
SFML::Network::IpAddress.from_string(“192.168.1.42”) SFML::Network::IpAddress.from_bytes(192, 168, 1, 42) SFML::Network::IpAddress::LOCALHOST # 127.0.0.1 SFML::Network::IpAddress::ANY # 0.0.0.0 SFML::Network::IpAddress::BROADCAST # 255.255.255.255 SFML::Network::IpAddress.local # local network IP
Constants
- ANY
-
0.0.0.0 — match any local interface.
- BROADCAST
-
255.255.255.255 — broadcast on the local subnet.
- LOCALHOST
-
127.0.0.1 — local-only.
- NONE
-
The 0.0.0.0 / empty placeholder address.
Public Class Methods
Source
# File lib/sfml/network/ip_address.rb, line 19 def self.from_bytes(a, b, c, d) wrap(C::Network.sfIpAddress_fromBytes(Integer(a), Integer(b), Integer(c), Integer(d))) end
Build from four octets: from_bytes(192, 168, 1, 42).
Source
# File lib/sfml/network/ip_address.rb, line 24 def self.from_integer(n) wrap(C::Network.sfIpAddress_fromInteger(Integer(n))) end
Build from a 32-bit packed integer.
Source
# File lib/sfml/network/ip_address.rb, line 14 def self.from_string(s) wrap(C::Network.sfIpAddress_fromString(s.to_s)) end
Parse from a dotted-decimal string like "192.168.1.42".
Source
# File lib/sfml/network/ip_address.rb, line 29 def self.local wrap(C::Network.sfIpAddress_getLocalAddress) end
The IP this machine sees on its local network.
Source
# File lib/sfml/network/ip_address.rb, line 35 def self.public(timeout: SFML::Time.zero) wrap(C::Network.sfIpAddress_getPublicAddress(timeout.to_native)) end
Public-facing IP. Performs an outbound query, so optionally cap with a timeout. Slow — minutes if the network is down.
Source
# File lib/sfml/network/ip_address.rb, line 40 def self.wrap(struct) ip = allocate ip.instance_variable_set(:@struct, struct) ip.freeze end
@!visibility private
Public Instance Methods
Source
# File lib/sfml/network/ip_address.rb, line 58 def ==(other) other.is_a?(IpAddress) && to_s == other.to_s end
Value equality — same dotted-decimal string.
Source
# File lib/sfml/network/ip_address.rb, line 63 def hash = to_s.hash # @!visibility private attr_reader :struct # The 0.0.0.0 / empty placeholder address. NONE = wrap(C::Network.sfIpAddress_None) # 0.0.0.0 — match any local interface. ANY = wrap(C::Network.sfIpAddress_Any) # 127.0.0.1 — local-only. LOCALHOST = wrap(C::Network.sfIpAddress_LocalHost) # 255.255.255.255 — broadcast on the local subnet. BROADCAST = wrap(C::Network.sfIpAddress_Broadcast) end
Returns the hash.
Source
# File lib/sfml/network/ip_address.rb, line 53 def to_i C::Network.sfIpAddress_toInteger(@struct) end
Packed 32-bit Integer view of the address.