socket_accept
Description
The socket_accept of Sockets for PHP accepts a connection on a socket.
Syntax
socket_accept( Socket $socket ): Socket|false
Parameters
socket
A Socket instance created with socket_create().
Return
Returns a new Socket instance on success, or false on error.
The actual error code can be retrieved by calling socket_last_error(). This error code may be passed to socket_strerror() to get a textual explanation of the error.
Examples
1 · socket
<? $domain = AF_INET; $type = SOCK_STREAM; $protocol = SOL_TCP; $serversocket = socket_create($domain, $type, $protocol); if($serversocket === false) { $error_code = socket_last_error(); $socket_strerror = socket_strerror($error_code); die("socket_create: $socket_strerror"); } $address = '127.0.0.1'; $port = 5000; $socket_bind = socket_bind($serversocket, $address, $port); if($socket_bind === false) { $error_code = socket_last_error($serversocket); $socket_strerror = socket_strerror($error_code); die("socket_bind: $socket_strerror"); } $socket_listen = socket_listen($serversocket); if($socket_listen === false) { $error_code = socket_last_error($serversocket); $socket_strerror = socket_strerror($error_code); die("socket_listen: $socket_strerror"); } $clientsocket = socket_create($domain, $type, $protocol); if($clientsocket === false) { $error_code = socket_last_error(); $socket_strerror = socket_strerror($error_code); die("socket_create: $socket_strerror"); } $socket_connect = socket_connect($clientsocket, $address, $port); if($socket_connect === false) { $error_code = socket_last_error($clientsocket); $socket_strerror = socket_strerror($error_code); die("socket_connect: $socket_strerror"); } $socket = socket_accept($serversocket); if($return === false) { $error_code = socket_last_error($socket); $socket_strerror = socket_strerror($error_code); die("socket_accept: $socket_strerror"); } var_export($socket); socket_close($socket); socket_close($clientsocket); socket_close($serversocket); ?>
\Socket::__set_state(array( ))
Links
Sockets
- socket_addrinfo_bind
- socket_addrinfo_connect
- socket_addrinfo_explain
- socket_addrinfo_lookup
- socket_atmark
- socket_bind
- socket_clear_error
- socket_close
- socket_cmsg_space
- socket_connect
- socket_create
- socket_create_listen
- socket_create_pair
- socket_export_stream
- socket_get_option
- socket_getopt
- socket_getpeername
- socket_getsockname
- socket_import_stream
- socket_last_error
- socket_listen
- socket_read
- socket_recv
- socket_recvfrom
- socket_recvmsg
- socket_select
- socket_send
- socket_sendmsg
- socket_sendto
- socket_set_block
- socket_set_nonblock
- socket_set_option
- socket_setopt
- socket_shutdown
- socket_strerror
- socket_write
- socket_wsaprotocol_info_export
- socket_wsaprotocol_info_import
- socket_wsaprotocol_info_release