Class: IPSocket
- Inherits:
-
BasicSocket
- Object
- IO
- BasicSocket
- IPSocket
- Defined in:
- mrbgems/mruby-socket/mrblib/socket.rb
Instance Attribute Summary
Attributes inherited from BasicSocket
Class Method Summary collapse
-
.getaddress(host) ⇒ Object
call-seq: IPSocket.getaddress(host) -> string.
Instance Method Summary collapse
-
#addr ⇒ Object
call-seq: ipsocket.addr -> [family, port, hostname, ip_address].
-
#peeraddr ⇒ Object
call-seq: ipsocket.peeraddr -> [family, port, hostname, ip_address].
-
#recvfrom(maxlen, flags = 0) ⇒ Object
call-seq: ipsocket.recvfrom(maxlen, flags=0) -> [data, addrinfo].
Methods inherited from BasicSocket
do_not_reverse_lookup, do_not_reverse_lookup=, for_fd, #initialize, #local_address, #recv_nonblock, #remote_address
Methods inherited from IO
#each, #each_byte, #each_char, #hash, open, pipe, popen, #pos=, #printf, read, #rewind
Constructor Details
This class inherits a constructor from BasicSocket
Class Method Details
.getaddress(host) ⇒ Object
call-seq:
IPSocket.getaddress(host) -> string
Returns the IP address of the given hostname as a string.
IPSocket.getaddress("localhost") #=> "127.0.0.1"
IPSocket.getaddress("www.ruby-lang.org") #=> "150.95.145.38"
474 475 476 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 474 def self.getaddress(host) Addrinfo.ip(host).ip_address end |
Instance Method Details
#addr ⇒ Object
call-seq:
ipsocket.addr -> [family, port, hostname, ip_address]
Returns the local address information as an array.
sock.addr #=> ["AF_INET", 12345, "localhost", "127.0.0.1"]
486 487 488 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 486 def addr Addrinfo.new(self.getsockname)._to_array end |
#peeraddr ⇒ Object
call-seq:
ipsocket.peeraddr -> [family, port, hostname, ip_address]
Returns the remote address information as an array.
sock.peeraddr #=> ["AF_INET", 80, "example.com", "93.184.216.34"]
498 499 500 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 498 def peeraddr Addrinfo.new(self.getpeername)._to_array end |
#recvfrom(maxlen, flags = 0) ⇒ Object
call-seq:
ipsocket.recvfrom(maxlen, flags=0) -> [data, addrinfo]
Receives data and sender information from the IP socket.
data, addr = sock.recvfrom(1024)
data, addr = sock.recvfrom(512, 0)
511 512 513 514 |
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 511 def recvfrom(maxlen, flags=0) msg, sa = _recvfrom(maxlen, flags) [ msg, Addrinfo.new(sa)._to_array ] end |