Code Extension to obtain remote host socket information */
Function getpeername ()
{
$ Remote_ip = $ remote_port = 0; // defines the ip address.
Socket_getpeername ($ this-> fd, $ remote_ip, $ remote_port); // return host information
Return array ($ remote_ip, $ remote_port); // returns an array
}
?>
<? Php Tutorial
If (false = ($ socket = @ socket_create (af_inet, sock_stream, sol_tcp) // if the socket fails to be created
{
Die ("couldn't create socket, error code is :". socket_last_error (). ", error message is :". socket_strerror (socket_last_error (); // output error information and error code
}
?>
<? Php
/* The following code expands to obtain the local host socket information */
Function getsockname ()
{
$ Remote_ip = $ remote_port = 0; // defines the ip address.
Socket_getsockname ($ this-> fd, $ remote_ip, $ remote_port); // return host information
Return array ($ remote_ip, $ remote_port); // returns an array
}
?>
<? Php
/* Define the array to be read */
$ Read = array ($ socket1, $ socket2 );
/* Perform the operation */
$ Num_changed_sockets = socket_select ($ read, $ write = null, $ response t = null, 0 );
If ($ num_changed_sockets = false)
{
/* Error handling */
}
Else if ($ num_changed_sockets> 0)
{
/* At least at one of the sockets something interesting happened */
}