Swoole\Coroutine\Socket::__construct

Declaration

<?php
Swoole\Coroutine\Socket::__construct(int $domain, int $type, int $protocol): Swoole\Coroutine\Socket

Parameters

domain

Select which protocol family that the socket will use for communication. Common domain protocols are AF_UNIX or AF_LOCAL for UnixSocket, AF_INET for IPv4 and AF_INET6 for IPv6. See the description for more details on domain communication types.

type

Specify the socket type, this is how you set the communication type to be used. Common types are SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET and SOCK_RAW. See the description for more details on socket types.

protocol

Specify which protocol to use with the socket. Normally there only exists one protocol per socket type, so 0 is suitable to use, this means use the same socket type for the protocol. However, other protocols can be used. Some common ones are IPPROTO_TCP, IPPROTO_UDP, IPPROTO_STCP and IPPROTO_TIPC.

Return

Returns a new coroutine socket object Swoole\Coroutine\Socket. If there was an error you can use the Swoole\Coroutine\Socket\Exception to catch them.


Description

Create a new Swoole\Coroutine\Socket object based on the domain family, type of socket to create and the protocol that is to be used. You handle connection operations once you have created the object.

For errors, you can either use the error class property $socket->errCode or use the Swoole\Coroutine\Socket\Exception to try-catch them.