⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socketserver.php

📁 flashget43的源代码 一个比较常用的下载程序
💻 PHP
字号:
<?PHPclass	socketServer extends patXMLServer_Dom{/***	end character for socket_read*	@var	integer	$readEndCharacter*/	var	$readEndCharacter	=	"\0";/***	time of purgening*	@var	integer	$time*/		var $timer = 0;	/***	request by flash received**	@access	private*	@param	integer	$clientId*	@param	string	$requestType*	@param	array	$requestParams*/	function	onReceiveRequest( $clientId, $requestType, $requestParams, $xml )	{		//echo "\nreceiving...\n";		//print_r($requestParams);				$GLOBALS['clientId'] = $clientId;				switch( $requestType )		{			case	"request":				$conn =& ChatServer::getConnection( $requestParams, $clientId );				$conn->process( $requestParams );				break;			case	"fileshare":				$this->sendFileShare( $requestParams, $xml);			case	"fault":				//	error management				break;		}				//do purge		$this->purge();	}		function purge()	{		if((time() - $this->timer) > $GLOBALS['fc_config']['msgRequestInterval'])		{			$this->timer = time() + 3600;			ChatServer::purge();			$this->timer = time();		}	}		function onStart()	{		$this->timer    = time();				$stmt = new Statement("DELETE FROM {$GLOBALS['fc_config']['db']['pref']}connections");		$stmt->process();	}		function onConnect( $clientId )	{		$data = array('clientId' => $clientId, 'ip' => $this->clientInfo[$clientId]['host']);		$this->saveClientConnection( $clientId, $data );	}		function onClose( $clientId )	{		//echo "\nonClose...\n";		//print_r($this->clientInfo);				//logout		$connection = $this->clientInfo[$clientId]['connection'];		if( $connection['id'] != null )		{					$connid = $connection['id'];			$userid = $connection['userid'];			$roomid = $connection['roomid'];						$GLOBALS['clientId'] = $clientId;						$conn =& ChatServer::getConnection( $this->clientInfo[$clientId]['connection'], $clientId );			$conn->doLogout();						$stmt = new Statement("DELETE FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE id = ?");			$stmt->process($connid);					//delete links			unset( $this->clientInfo['connid'][$connid] ); 			unset( $this->clientInfo['userid'][$userid] ); 			unset( $this->clientInfo['roomid'][$roomid][$clientId] );		}		} 		function sendFileShare( $params, $xml )	{		$id = -1;		if( isset($params['a']) ) $id = array($this->clientInfo['userid'][$params['a']]);		else if ( isset($params['r']) ) $id = $this->clientInfo['roomid'][$params['r']];				$this->send4ID($id, null, $xml);		}		function sendMessage( $message )	{		if(!$message->created) 			$message->created = date("YmdHis");				$message->id = 1; //on insert message get id !!!???				$id = -1;				$toconn = $message->toconnid != null;		$touser = $message->touserid != null;		if( $toconn || $touser )		{ 			$id = array();						if( $toconn ) array_push($id, $this->clientInfo['connid'][$message->toconnid]);			if( $touser ) array_push($id, $this->clientInfo['userid'][$message->touserid]);						$id = array_unique( $id );  		}			else if($message->toroomid != null) $id = $this->clientInfo['roomid'][$message->toroomid];				//echo "\nid ".$id." msg ".$message->command." to uid ".$message->touserid." to cid ".$message->toconnid." to rid ".$message->toroomid."\n";				$this->send4ID($id, $message, null);	}		function send4ID( $IDs, $message, $xml)	{		//for all		$clients = $this->clientInfo['connid'];		//for some		if(is_array($IDs)) $clients = $IDs;				foreach($clients as $v) 		{			$data = ($xml == null)? $message->toXML($this->clientInfo[$v]['connection']['tzoffset']) : $xml;			$sxml = "<response id=\"".$this->clientInfo[$v]['connection']['id']."\">".$data."</response>";			$this->sendXMLResponse($v, $sxml);						//echo "XML >> $sxml\n";			}		}		function saveClientConnection( $clientId, $data )	{		if( !isset($this->clientInfo[$clientId]['connection']) )		{					$this->clientInfo[$clientId]['connection'] = array(										'clientId'  => $data['clientId'],										'id'		=> $data['id'],										'userid'	=> $data['userid'],										'roomid'	=> $data['roomid'],										'color'		=> $data['color'],										'state'		=> $data['state'],										'start'		=> $data['start'],										'lang'		=> $data['lang'],										'ip' 		=> $data['ip'],										'tzoffset'	=> $data['tzoffset']					);		}		else		{			$this->clientInfo[$clientId]['connection'] = $data;		}				//create links for faster searching		if($data['id'] != null) $this->clientInfo['connid'][$data['id']] = $clientId;		if($data['userid'] != null) $this->clientInfo['userid'][$data['userid']] = $clientId;		if($data['roomid'] != null) 		{			if(!is_array($this->clientInfo['roomid'][$data['roomid']])) $this->clientInfo['roomid'][$data['roomid']] = array();			$this->clientInfo['roomid'][$data['roomid']][$clientId] = $clientId;		}			//print_r($this->clientInfo);	}}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -