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

IO::Socket

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 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 "PeerAddr" field is defined, connect is executed.

And if "LocalPort" field is defined, bind and listen are executed.

And returns the new object.

Options:

The following options are available adding the options for IO::Socket#new method are available.

  • 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 : string

    A peer 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.

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 peer 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 peer 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 peer 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.

accept

method accept : IO::Socket::IP ($peer_ref : Sys::Socket::Sockaddr[] = undef);

Calls accept method of its super class given the argument given to this method and returns its return value.

Well Known Child Classes

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License