Name
SPVM::IO::Socket::IP - IPv4/IPv6 Sockets
Usage
use IO::Socket::IP;
use Sys::Socket::Constant as SOCKET;
# Client Socket
my $host = "www.perl.org";
my $port = 80;
my $socket = IO::Socket::IP->new({
PeerAddr => $host,
PeerPort => $port
});
# Server Socket
my $socket = IO::Socket::IP->new({
LocalAddr => 'localhost',
LocalPort => 9000,
Listen => 5,
});
# IPv6 Client Socket
my $host = "google.com";
my $port = 80;
my $socket = IO::Socket::IP->new({
PeerAddr => $host,
PeerPort => $port,
Domain => SOCKET->AF_INET6,
});
Description
IO::Socket::INET class in SPVM represents an IPv4 or IPv6 socket.
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 peer address.
PeerPort
has PeerPort : protected int;
A peer port.
ReuseAddr
has ReuseAddr : protected byte;
The value of SO_REUSEADDR socket option.
ReusePort
has ReusePort : protected byte;
The value of SO_REUSEPORT
socket option.
Broadcast
has Broadcast : protected byte;
The value of SO_BROADCAST socket option.
V6Only
has V6Only : byte;
The value of IPV6_V6ONLY socket option.
V6OnlySpecified
has V6OnlySpecified : byte;
If this field is a true value, V6Only
option is specified on "init" method.
Class Methods
new
static method new : IO::Socket::IP ($options : object[] = undef);
Creates a new IO::Socket::IP object given the options $options, and returns it.
This object represents a IPv4 or IPv6 domain socket.
If "ReuseAddr" field is a true value, SO_REUSEADD
option of this socket is set to 1.
If "ReusePort" field is a true value, SO_REUSEPORT
option of this socket is set to 1.
If "Broadcast" field is a true value, SO_BROADCAST
option of this socket is set to 1.
If the value of "V6OnlySpecified" field is a true value, IPV6_V6ONLY
option of this socket is set to the following value.
If the value of "V6Only" field is a true value, it is set to 1, otherwise 0.
If "PeerAddr" field is specified, this object becomes a client socket. It calls connect method.
If Listen field is a positive value, this object becomes a server socket. It calls bind method and listen method.
See "init" method about the options $options.
Instance Methods
init
protected method init : void ($options : object[] = undef);
Initializes fields of this instance given the option $options.
Options:
The following options are available adding the options for IO::Socket#init method are available.
[Name][Type][Default Value]
ReuseAddr
: string = undef"ReuseAddr" field is set to this value.
ReusePort
: Int = 0"ReusePort" field is set to this value.
Broadcast
: Int = 0"Broadcast" field is set to this value.
PeerAddr
: string = undef"PeerAddr" field is set to this value.
PeerPort
: Int = 0"PeerPort" field is set to this value.
LocalAddr
: string = undef"LocalAddr" field is set to this value.
LocalPort
: Int = 0"LocalPort" field is set to this value.
V6Only
: Int = undefIf this option is specified, "V6OnlySpecified" is set to 1 and "V6Only" field is set to this value.
Domain field is set to AF_INET
if Domain
option is not specified.
Proto field is set to IPPROTO_TCP
if Proto
option is not specified.
Type field is set to the following value according to the value of Proto field.
If the value of Proto
is IPPROTO_TCP
, the Type
field is set to SOCK_STREAM
.
If the value of Proto
is IPPROTO_UDP
, the Type
field is set to SOCK_DGRAM
.
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.
Implementation:
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 peer address.
Implementation:
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 peer host name.
Implementation:
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 peer port.
Implementation:
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.
accept
method accept : IO::Socket::IP ($peer_ref : Sys::Socket::Sockaddr[] = undef);
This method is the same as accept method, but its return type is different.
Well Known Child Classes
See Also
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License