Socket typesΒΆ

Async Socket Library provides two types of sockets - client and server. The client socket can be either persistent or non-persistent. The recommended way of creating sockets of different types in source code is by using AsyncSocketFactory:

1
2
3
4
5
6
use AsyncSockets\Socket\AsyncSocketFactory;

$factory = new AsyncSocketFactory();

$client  = $factory->createSocket(AsyncSocketFactory::SOCKET_CLIENT);
$server  = $factory->createSocket(AsyncSocketFactory::SOCKET_SERVER);

You may pass additional options via second argument of createSocket():

1
2
3
4
5
6
7
8
9
use AsyncSockets\Socket\AsyncSocketFactory;

$factory = new AsyncSocketFactory();
$client  = $factory->createSocket(
    AsyncSocketFactory::SOCKET_CLIENT,
    [
        AsyncSocketFactory::SOCKET_OPTION_IS_PERSISTENT => true
    ]
);

The above code will create persistent socket. See persistent sockets to get detailed information.

All available options are now linked with persistent sockets.