Server
Less than 1 minute
Server
Abstract socket server class.
class ServerProvides the core logic for creating a socket server that listens for incoming connections and manages client communication. Subclasses must implement connection and data handling methods for specific server behaviors.
Properties
maxBufferSize
Maximum buffer size for receiving data from sockets.
protected int $maxBufferSizepublic $sockets
Array of active socket resources managed by the server.
protected array $socketsrunning
Indicates whether the server is currently running.
protected bool $runningMethods
__construct
Constructs a new socket server and initializes the master socket.
public __construct(string $addr, int $port, int $bufferLength = 2048): voidParameters
| Parameter | Type | Description |
|---|---|---|
$addr | string | the address to bind the server to |
$port | int | the port to listen on |
$bufferLength | int | the buffer size for receiving data (default: 2048) |
run
Server main loop.
public run(?int $timeout): voidParameters
| Parameter | Type | Description |
|---|---|---|
$timeout | int |
connecting
protected connecting(string $remoteAddr, int $remotePort, string $localAddr, int $localPort): boolParameters
| Parameter | Type | Description |
|---|---|---|
$remoteAddr | string | |
$remotePort | int | |
$localAddr | string | |
$localPort | int |
connected
protected connected(\Socket $client): voidParameters
| Parameter | Type | Description |
|---|---|---|
$client | \Socket |
process
protected process(string $message): voidParameters
| Parameter | Type | Description |
|---|---|---|
$message | string |
closed
protected closed(\Socket $client): voidParameters
| Parameter | Type | Description |
|---|---|---|
$client | \Socket |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:23 +0000