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 $maxBufferSizeType: int
master
The master socket resource for the server, or false if creation failed.
protected false|\Socket $masterType: false|Socket
sockets
Array of active socket resources managed by the server.
protected array $socketsType: array
running
Indicates whether the server is currently running.
protected bool $runningType: bool
Methods
__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): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$timeout | int |
connecting
protected connecting(string $remoteAddr, int $remotePort, string $localAddr, int $localPort): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$remoteAddr | string | |
$remotePort | int | |
$localAddr | string | |
$localPort | int |
connected
protected connected(\Socket $client): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$client | Socket |
process
protected process(string $message): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$message | string |
closed
protected closed(\Socket $client): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$client | Socket |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000