Server
Less than 1 minute
Server
The socket server class.
Creates a socket server that listens on an address and port for incoming connections.
- Full name:
\Hazaar\Socket\Server
- This class is an Abstract class
Properties
maxBufferSize
protected int $maxBufferSize
master
protected \Socket $master
sockets
protected \Socket[] $sockets
running
protected bool $running
Methods
__construct
public __construct(string $addr, int $port, int $bufferLength = 2048): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$addr | string | |
$port | int | |
$bufferLength | int |
run
Server main loop.
public run(?int $timeout = null): void
Parameters:
Parameter | Type | Description |
---|---|---|
$timeout | ?int |
connecting
Incomming connection request handler.
protected connecting(string $remoteAddr, int $remotePort, string $localAddr, int $localPort): bool
Event called when a connection request is received. Should return true or false indicating if the connection should be accepted.
- This method is abstract.
Parameters:
Parameter | Type | Description |
---|---|---|
$remoteAddr | string | |
$remotePort | int | |
$localAddr | string | |
$localPort | int |
connected
Incomming connection handlers.
protected connected(\Socket $client): void
Event called when a connection is established and data can begin to be sent/received.
- This method is abstract.
Parameters:
Parameter | Type | Description |
---|---|---|
$client | \Socket |
process
Incoming data handler.
protected process(string $message): void
Called immediately when data is recieved.
- This method is abstract.
Parameters:
Parameter | Type | Description |
---|---|---|
$message | string |
closed
Close connection handler.
protected closed(\Socket $client): void
Called after the connection is closed.
- This method is abstract.
Parameters:
Parameter | Type | Description |
---|---|---|
$client | \Socket |
Automatically generated on 2024-11-14