/** "appName" => "patServer", /** /** /** /** /** /** /** /** /** /** /** /** /** /** /** $this->serverInfo["domain"] = $domain; set_time_limit( 0 ); /** /** $this->debug = true; /** // adress may be reused // bind the socket // listen on selected port $this->sendDebugMessage( "Listening on port ".$this->port.". Server started at ".date( "H:i:s", time() ) ); // this allows the shutdown function to check whether the server is already shut down if( method_exists( $this, "onStart" ) ) $this->serverInfo["started"] = time(); while( true ){ // fetch all clients that are awaiting connections // block and wait for data or new connection if( $ready === false ){ // check for new connection // check for maximum amount of connections if( method_exists( $this, "onConnectionRefused" ) ) $this->closeConnection( $newClient ); if( --$ready continue; // check all clients for incoming data
* patServer
* PHP socket server base class
* Events that can be handled:
* * onStart
* * onConnect
* * onConnectionRefused
* * onClose
* * onShutdown
* * onReceiveData
*
* @version 1.1
* @author Stephan Schmidt
* @package patServer
*/
class patServer{
/**
* information about the project
* @var array $systemVars
*/
var $systemVars = array(
"appVersion" => "1.1",
"author" => array("Stephan Schmidt
);
* port to listen
* @var integer $port
*/
var $port = 10000;
* domain to bind to
* @var string $domain
*/
var $domain = "localhost";
* maximum amount of clients
* @var integer $maxClients
*/
var $maxClients = -1;
* buffer size for socket_read
* @var integer $readBufferSize
*/
var $readBufferSize = 128;
* end character for socket_read
* @var integer $readEndCharacter
*/
var $readEndCharacter = "
";
* maximum of backlog in queue
* @var integer $maxQueue
*/
var $maxQueue = 500;
* debug mode
* @var boolean $debug
*/
var $debug = true;
* debug mode
* @var string $debugMode
*/
var $debugMode = "text";
* debug destination (filename or stdout)
* @var string $debugDest
*/
var $debugDest = "stdout";
* empty array, used for socket_select
* @var array $null
*/
var $null = array();
* all file descriptors are stored here
* @var array $clientFD
*/
var $clientFD = array();
* needed to store client information
* @var array $clientInfo
*/
var $clientInfo = array();
* needed to store server information
* @var array $serverInfo
*/
var $serverInfo = array();
* amount of clients
* @var integer $clients
*/
var $clients = 0;
* create a new socket server
*
* @access public
* @param string $domain domain to bind to
* @param integer $port port to listen to
*/
function patServer( $domain = "localhost", $port = 10000 ){
$this->domain = $domain;
$this->port = $port;
$this->serverInfo["port"] = $port;
$this->serverInfo["servername"] = $this->systemVars["appName"];
$this->serverInfo["serverversion"] = $this->systemVars["appVersion"];
}
* set maximum amount of simultaneous connections
*
* @access public
* @param int $maxClients
*/
function setMaxClients( $maxClients ){
$this->maxClients = $maxClients;
}
* set debug mode
*
* @access public
* @param mixed $debug [text|htmlfalse]
* @param string $dest destination of debug message (stdout to output or filename if log should be written)
*/
function setDebugMode( $debug, $dest = "stdout" ){
if( $debug === false ){
$this->debug = false;
return true;
}
$this->debugMode = $debug;
$this->debugDest = $dest;
}
* start the server
*
* @access public
* @param int $maxClients
*/
function start(){
$this->initFD = @socket_create( AF_INET, SOCK_STREAM, 0 );
if( !$this->initFD )
die( "patServer: Could not create socket." );
socket_setopt( $this->initFD, SOL_SOCKET, SO_REUSEADDR, 1 );
if(!@socket_bind( $this->initFD, $this->domain, $this->port ) ){
@socket_close( $this->initFD );
die( "patServer: Could not bind socket to ".$this->domain." on port ".$this->port." ( ".$this->getLastSocketError( $this->initFd )." )." );
}
if(!@socket_listen( $this->initFD, $this->maxQueue ) )
die( "patServer: Could not listen ( ".$this->getLastSocketError( $this->initFd )." )." );
$GLOBALS["_patServerStatus"] = "running";
// this ensures that the server will be sutdown correctly
register_shutdown_function( array( $this, "shutdown" ) );
$this->onStart();
$this->serverInfo["status"] = "running";
$readFDs = array();
array_push( $readFDs, $this->initFD );
for( $i = 0; $i clientFD ); $i++ )
if( isset( $this->clientFD[$i] ) )
array_push( $readFDs, $this->clientFD[$i] );
$ready = @socket_select( $readFDs, $this->null, $this->null, NULL );
$this->sendDebugMessage( "socket_select failed." );
$this->shutdown();
}
if( in_array( $this->initFD, $readFDs ) ){
$newClient = $this->acceptConnection( $this->initFD );
if( $this->maxClients > 0 ){
if( $this->clients > $this->maxClients ){
$this->sendDebugMessage( "Too many connections." );
$this->onConnectionRefused( $newClient );
}
}
}
for( $i = 0; $i clientFD ); $i++ ){

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

WebStorm Mac版
便利なJavaScript開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

DVWA
Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

Dreamweaver Mac版
ビジュアル Web 開発ツール
