Name
SPVM::IO::Socket::IP - IPv4/IPv6 Sockets
Usage
use IO::Socket::IP;
use Sys::Socket;
use Sys::Socket::Constant as SOCKET;
# Client Socket
my $host = "www.perl.org";
my $port = 80;
my $io_socket = IO::Socket::IP->new({
PeerAddr => $host,
PeerPort => $port
});
# Server Socket
my $io_socket = IO::Socket::IP->new({
LocalAddr => 'localhost',
LocalPort => 9000,
Listen => 5,
});
# IPv6 Client Socket
my $host = "google.com";
my $port = 80;
my $io_socket = IO::Socket::IP->new({
PeerAddr => $host,
PeerPort => $port,
Domain => SOCKET->AF_INET6,
});
Description
IO::Socket::INET class in SPVM has methods to create IPv4/IPv6 Sockets.
Super Class
Fields
LocalAddr
has LocalAddr : protected string;
A local address.
LocalPort
has LocalPort : protected int;
A local port.
PeerAddr
has PeerAddr : protected string;
A remote address.
PeerPort
has PeerPort : protected int;
A remote port
ReuseAddr
has ReuseAddr : protected int;
If this field is a true value, The SO_REUSEADDR socket option is set.
ReusePort
has ReusePort : protected int;
If this field is a true value, The SO_REUSEPORT
socket option is set.
Broadcast
has Broadcast : protected int;
If this field is a true value, The SO_BROADCAST socket option is set.
Class Methods
new
static method new : IO::Socket::IP ($options : object[] = undef);
Creates a new IO::Socket::IP object.
And creates a socket.
And if "ReuseAddr" field is defined, connect is executed.
And if "LocalPort" field is defined, bind and listen are executed.
And returns the new object.
Options:
ReuseAddr
: string"ReuseAddr" field is set to this value.
ReusePort
: Int"ReusePort" field is set to this value.
Broadcast
: Int"Broadcast" field is set to this value.
PeerAddr
: stringA remote address.
"PeerAddr" field is set to this value.
PeerPort
: Int"PeerPort" field is set to this value.
LocalAddr
: string"LocalAddr" field is set to this value.
LocalPort
: Int"LocalPort" field is set to this value.
Adding the above options, options in IO::Socket#new method are available.
Instance Methods
init
protected method init : void ($options : object[] = undef);
Initializes this instance.
sockaddr
method sockaddr : Sys::Socket::In_addr_base ();
Returns the local address.
If "Domain" field is AF_INET
, this method calls IO::Socket::IP::Import::IPv4#sockaddr method.
If "Domain" field is AF_INET6
, this method calls IO::Socket::IP::Import::IPv6#sockaddr method.
sockhost
method sockhost : string ();
Returns the local host name.
If "Domain" field is AF_INET
, this method calls IO::Socket::IP::Import::IPv4#sockhost method.
If "Domain" field is AF_INET6
, this method calls IO::Socket::IP::Import::IPv6#sockhost method.
sockport
method sockport : int ();
Returns the local port.
If "Domain" field is AF_INET
, this method calls IO::Socket::IP::Import::IPv4#sockport method.
If "Domain" field is AF_INET6
, this method calls IO::Socket::IP::Import::IPv6#sockport method.
peeraddr
method peeraddr : Sys::Socket::In_addr_base ();
Return the remote address.
If "Domain" field is AF_INET
, this method calls IO::Socket::IP::Import::IPv4#peeraddr method.
If "Domain" field is AF_INET6
, this method calls IO::Socket::IP::Import::IPv6#peeraddr method.
peerhost
method peerhost : string ();
Returns the remote host name.
If "Domain" field is AF_INET
, this method calls IO::Socket::IP::Import::IPv4#peerhost method.
If "Domain" field is AF_INET6
, this method calls IO::Socket::IP::Import::IPv6#peerhost method.
peerport
method peerport : int ();
Returns the remote port.
If "Domain" field is AF_INET
, this method calls IO::Socket::IP::Import::IPv4#peerport method.
If "Domain" field is AF_INET6
, this method calls IO::Socket::IP::Import::IPv6#peerport method.
Well Known Child Classes
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License