1 | <?php |
||
10 | abstract class AbstractClient extends AbstractSocket { |
||
11 | |||
12 | /** |
||
13 | * The peer's name as `<address>:<port>`, |
||
14 | * or `<pid>:0` for Unix sockets, |
||
15 | * or `?<id>` if a name can't be derived (e.g. the socket is closed). |
||
16 | * |
||
17 | * @see getPeerName() |
||
18 | * |
||
19 | * @return string |
||
20 | */ |
||
21 | public function __toString () { |
||
29 | |||
30 | /** |
||
31 | * Connects the socket to a peer. |
||
32 | * For datagram sockets this sets the target recipient. |
||
33 | * |
||
34 | * For non-blocking sockets, the `SOCKET_EINPROGRESS` and `SOCKET_EWOULDBLOCK` errors |
||
35 | * are ignored and cleared, because they're expected. |
||
36 | * |
||
37 | * @see https://php.net/socket_connect |
||
38 | * |
||
39 | * @param string $address The remote network address, or local Unix file name. |
||
40 | * @param int $port The remote port. Unix sockets ignore this entirely. |
||
41 | * @return $this |
||
42 | * @throws SocketError |
||
43 | */ |
||
44 | public function connect (string $address, int $port = 0) { |
||
55 | |||
56 | /** |
||
57 | * The peer's address and port, or Unix PID and port `0`. |
||
58 | * |
||
59 | * @see https://php.net/socket_getpeername |
||
60 | * |
||
61 | * @return array `[ 0 => address, 1 => port ]` |
||
62 | * @throws SocketError |
||
63 | */ |
||
64 | public function getPeerName (): array { |
||
73 | |||
74 | /** |
||
75 | * Sends data to the remote peer. |
||
76 | * |
||
77 | * @see https://php.net/socket_send |
||
78 | * |
||
79 | * @param string $data |
||
80 | * @param int $flags `MSG_*` |
||
81 | * @return int Total bytes sent. |
||
82 | * @throws SocketError |
||
83 | */ |
||
84 | public function send (string $data, int $flags = 0): int { |
||
91 | |||
92 | /** |
||
93 | * Sends all data (forced blocking). |
||
94 | * |
||
95 | * @param string $data |
||
96 | * @return $this |
||
97 | * @throws SocketError `int` total bytes sent is set as the extra data. |
||
98 | */ |
||
99 | public function write (string $data) { |
||
113 | |||
114 | } |
||
115 |