Documentation

Socket

Table of Contents

Namespaces

Internal
SocketAddress

Interfaces

ServerSocket
ServerSocketFactory
Socket
A `ReadableStream` allows reading byte streams in chunks.
SocketAddress
SocketConnector
SocketPool
Allows pooling of connections for stateless protocols.
UdpSocket

Classes

BindContext
Certificate
CidrMatcher
ClientTlsContext
ConnectContext
ConnectException
Thrown if connecting fails.
DnsSocketConnector
InternetAddress
PendingAcceptError
Thrown in case a second read operation is attempted while another read operation is still pending.
PendingReceiveError
Thrown in case a second read operation is attempted while another receive operation is still pending.
ResourceServerSocket
ResourceServerSocketFactory
ResourceSocket
ResourceUdpSocket
RetrySocketConnector
ServerTlsContext
SocketException
Socks5SocketConnector
StaticSocketConnector
Connector that connects to a statically defined URI instead of the URI passed to the {@code connect()} call.
TlsException
Thrown if TLS can't be properly negotiated or is not supported on the given socket.
TlsInfo
Exposes a connection's negotiated TLS parameters.
UnixAddress
UnlimitedSocketPool
SocketPool implementation that doesn't impose any limits on concurrent open connections.

Enums

InternetAddressVersion
SocketAddressType
TlsState

Functions

listen()  : ResourceServerSocket
Listen for client connections on the specified server address.
bindUdpSocket()  : ResourceUdpSocket
Create a new Datagram (UDP server) on the specified server address.
socketConnector()  : SocketConnector
Set or access the global SocketConnector instance.
connect()  : Socket
Establish a socket connection to the specified URI.
connectTls()  : Socket
Establish a socket connection to the specified URI and enable TLS.
createSocketPair()  : ResourceSocket}
Returns a pair of connected stream socket resources.
hasTlsAlpnSupport()  : bool
hasTlsSecurityLevelSupport()  : bool

Functions

listen()

Listen for client connections on the specified server address.

listen(SocketAddress|string $address[, BindContext|null $bindContext = null ][, positive-int $chunkSize = ResourceSocket::DEFAULT_CHUNK_SIZE ]) : ResourceServerSocket

If you want to accept TLS connections, you have to use yield $socket->setupTls() after accepting new clients.

Parameters
$address : SocketAddress|string

URI in scheme://host:port format. TCP is assumed if no scheme is present.

$bindContext : BindContext|null = null

Context options for listening.

$chunkSize : positive-int = ResourceSocket::DEFAULT_CHUNK_SIZE

Chunk size for the accepted sockets.

Tags
throws
SocketException

If binding to the specified URI failed.

Return values
ResourceServerSocket

bindUdpSocket()

Create a new Datagram (UDP server) on the specified server address.

bindUdpSocket(InternetAddress|string $address[, BindContext|null $bindContext = null ][, positive-int $limit = ResourceUdpSocket::DEFAULT_LIMIT ]) : ResourceUdpSocket
Parameters
$address : InternetAddress|string

URI in scheme://host:port format. UDP is assumed if no scheme is present.

$bindContext : BindContext|null = null

Context options for listening.

$limit : positive-int = ResourceUdpSocket::DEFAULT_LIMIT

Maximum size for received messages.

Tags
throws
SocketException

If binding to the specified URI failed.

Return values
ResourceUdpSocket

connect()

Establish a socket connection to the specified URI.

connect(SocketAddress|string $uri[, ConnectContext|null $context = null ][, Cancellation|null $cancellation = null ]) : Socket
Parameters
$uri : SocketAddress|string

URI in scheme://host:port format. TCP is assumed if no scheme is present.

$context : ConnectContext|null = null

Socket connect context to use when connecting.

$cancellation : Cancellation|null = null
Tags
throws
ConnectException
throws
CancelledException
Return values
Socket

connectTls()

Establish a socket connection to the specified URI and enable TLS.

connectTls(SocketAddress|string $uri[, ConnectContext|null $context = null ][, Cancellation|null $cancellation = null ]) : Socket
Parameters
$uri : SocketAddress|string

URI in scheme://host:port format. TCP is assumed if no scheme is present.

$context : ConnectContext|null = null

Socket connect context to use when connecting.

$cancellation : Cancellation|null = null
Tags
throws
ConnectException
throws
TlsException
throws
CancelledException
Return values
Socket

hasTlsSecurityLevelSupport()

hasTlsSecurityLevelSupport() : bool
Return values
bool

        
On this page

Search results