It's a modification of the socket module.
I've added 3 functions.
PHP Code:
/* Opens a new listenning connection bind to hostname:port via protocol (either SOCKET_TCP or SOCKET_UDP),
* returns a socket (positive) or negative or zero on error.
* States of error:
* 0 - no error
* 1 - error while creating socket
* 2 - couldn't resolve hostname
* 3 - couldn't connect to given hostname:port
*/
native socket_listen(const _hostname[], _port, _protocol = SOCKET_TCP, &_error);
PHP Code:
/* Set a socket in unblocking mode */
native socket_unblock(_socket);
PHP Code:
native socket_close(_socket);
/* Accept a connection on a listenning socket
* returns a socket (positive) or negative or zero on error. */
native socket_accept(_socket);
With UDP you've just to create a listenning socket to get incoming messages and create a socket to reply.
With TCP you've to create a listenning socket and accept connections.
To avoid socket_accept block. Set the listenning socket to nonblocking mode with socket_unblock.
Todo:
add: incoming packet address in socket_accept
add: function to see the address when receive a package of a listenning socket.