is->clients; }
/** * send data to a client * * @access public * @param int $clientId ID of the client * @param string $data data to send * @param boolean $debugData flag to indicate whether data that is written to socket should also be sent as debug message */ function sendData( $clientId, $data, $debugData = true ){ if( !isset( $this->clientFD[$clientId] ) || $this->clientFD[$clientId] == NULL ) return false;
if( $debugData ) $this->sendDebugMessage( "sending: \"" . $data . "\" to: $clientId" );
if(!@socket_write( $this->clientFD[$clientId], $data ) ) $this->sendDebugMessage( "Could not write ''".$data."'' client ".$clientId." ( ".$this->getLastSocketError( $this->clientFD[$clientId] )." )." ); }
/** * send data to all clients * * @access public * @param string $data data to send * @param array $exclude client ids to exclude */ function broadcastData( $data, $exclude = array(), $debugData = true ){ if( !empty( $exclude ) && !is_array( $exclude ) ) $exclude = array( $exclude );
for( $i = 0; $i < count( $this->clientFD ); $i++ ){ if( isset( $this->clientFD[$i] ) && $this->clientFD[$i] != NULL && !in_array( $i, $exclude ) ){ if( $debugData ) $this->sendDebugMessage( "sending: \"" . $data . "\" to: $i" );
if(!@socket_write( $this->clientFD[$i], $data ) ) $this->sendDebugMessage( "Could not write ''".$data."'' client ".$i." ( ".$this->getLastSocketError( $this->clientFD[$i] )." )." ); } } }
/** * get current information about a client * * @access public * @param int $clientId ID of the client * @return array $info information about the client */ function getClientInfo( $clientId ){ if( !isset( $this->clientFD[$clientId] ) || $this->clientFD[$clientId] == NULL ) return false; return $this->clientInfo[$clientId]; }
/** * send a debug message * * @access private * @param string $msg message to debug */ function sendDebugMessage( $msg ){ if( !$this->debug ) return false;
$msg = date( "Y-m-d H:i:s", time() ) . " " . $msg;
switch( $this->debugMode ){ case "text": $msg = $msg."\n"; break; case "html": $msg = htmlspecialchars( $msg ) . "<br />\n"; break; }
if( $this->debugDest == "stdout" || empty( $this->debugDest ) ){ echo $msg; flush(); return true; }
error_log( $msg, 3, $this->debugDest ); return t |