• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP getprotobyname函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中getprotobyname函数的典型用法代码示例。如果您正苦于以下问题:PHP getprotobyname函数的具体用法?PHP getprotobyname怎么用?PHP getprotobyname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了getprotobyname函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Constructor.
  *
  * @param array $config Socket configuration, which will be merged with the base configuration
  * @see CakeSocket::$_baseConfig
  */
 public function __construct($config = array())
 {
     $this->config = array_merge($this->_baseConfig, $config);
     if (!is_numeric($this->config['protocol'])) {
         $this->config['protocol'] = getprotobyname($this->config['protocol']);
     }
 }
开发者ID:ronaldsalazar23,项目名称:ComercialChiriguano,代码行数:13,代码来源:CakeSocket.php


示例2: _connect

 private function _connect()
 {
     if ($this->connection = socket_create($this->socket_domain, SOCK_STREAM, $this->socket_domain > 1 ? getprotobyname('tcp') : 0)) {
         if (socket_connect($this->connection, $this->socket_address, $this->socket_port)) {
             $this->setNonBlock();
             // $this->connection); // устанавливаем неблокирующий режим работы сокета
             return $this->connected = true;
         } else {
             $error = socket_last_error($this->connection);
             socket_clear_error($this->connection);
             switch ($error) {
                 case SOCKET_ECONNREFUSED:
                 case SOCKET_ENOENT:
                     // если отсутствует файл сокета, либо соединиться со слушающим сокетом не удалось - возвращаем false
                     $this->disconnect();
                     return false;
                 default:
                     // в иных случаях кидаем необрабатываемое исключение
                     throw new \Exception(socket_strerror($error));
             }
         }
     }
     // @TODO delete next line...
     trigger_error('Client connect failed', E_USER_ERROR);
     return false;
 }
开发者ID:maestroprog,项目名称:esockets-php,代码行数:26,代码来源:Client.php


示例3: testConstruct

/**
 * testConstruct method
 *
 * @return void
 */
	public function testConstruct() {
		$this->Socket = new CakeSocket();
		$config = $this->Socket->config;
		$this->assertSame($config, array(
			'persistent'	=> false,
			'host'			=> 'localhost',
			'protocol'		=> getprotobyname('tcp'),
			'port'			=> 80,
			'timeout'		=> 30
		));

		$this->Socket->reset();
		$this->Socket->__construct(array('host' => 'foo-bar'));
		$config['host'] = 'foo-bar';
		$this->assertSame($this->Socket->config, $config);

		$this->Socket = new CakeSocket(array('host' => 'www.cakephp.org', 'port' => 23, 'protocol' => 'udp'));
		$config = $this->Socket->config;

		$config['host'] = 'www.cakephp.org';
		$config['port'] = 23;
		$config['protocol'] = 17;

		$this->assertSame($this->Socket->config, $config);
	}
开发者ID:hungnt88,项目名称:5stars-1,代码行数:30,代码来源:CakeSocketTest.php


示例4: connect

 /**
  * Gets the OrientSocket, and establishes the connection if required.
  *
  * @return \PhpOrient\Protocols\Binary\OrientSocket
  *
  * @throws SocketException
  * @throws PhpOrientWrongProtocolVersionException
  */
 public function connect()
 {
     if (!$this->connected) {
         if (empty($this->hostname) && empty($this->port)) {
             throw new SocketException('Can not initialize a connection ' . 'without connection parameters');
         }
         if (!extension_loaded("sockets")) {
             throw new SocketException('Can not initialize a connection ' . 'without socket extension enabled. Please check you php.ini');
         }
         $this->_socket = @socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
         socket_set_block($this->_socket);
         socket_set_option($this->_socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => self::READ_TIMEOUT, 'usec' => 0));
         socket_set_option($this->_socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => self::WRITE_TIMEOUT, 'usec' => 0));
         $x = @socket_connect($this->_socket, $this->hostname, $this->port);
         if (!is_resource($this->_socket) || $x === false) {
             throw new SocketException($this->getErr() . PHP_EOL);
         }
         $protocol = Reader::unpackShort($this->read(2));
         if ($protocol > $this->protocolVersion) {
             throw new PhpOrientWrongProtocolVersionException('Protocol version ' . $protocol . ' is not supported.');
         }
         //protocol handshake
         $this->protocolVersion = $protocol;
         $this->connected = true;
     }
     return $this;
 }
开发者ID:emman-ok,项目名称:PhpOrient,代码行数:35,代码来源:OrientSocket.php


示例5: send

 /**
  * Method send
  *
  * @param string $raw_text
  *
  * @return string $return_text
  */
 public function send($raw_text)
 {
     if (!empty($raw_text)) {
         $this->raw_text = $raw_text;
         $xw = new xmlWriter();
         $xw->openMemory();
         $xw->startDocument('1.0');
         $xw->startElement('wordsegmentation');
         $xw->writeAttribute('version', '0.1');
         $xw->startElement('option');
         $xw->writeAttribute('showcategory', '1');
         $xw->endElement();
         $xw->startElement('authentication');
         $xw->writeAttribute('username', $this->username);
         $xw->writeAttribute('password', $this->password);
         $xw->endElement();
         $xw->startElement('text');
         $xw->writeRaw($this->raw_text);
         $xw->endElement();
         $xw->endElement();
         $message = iconv("utf-8", "big5", $xw->outputMemory(true));
         //send message to CKIP server
         set_time_limit(60);
         $protocol = getprotobyname("tcp");
         $socket = socket_create(AF_INET, SOCK_STREAM, $protocol);
         socket_connect($socket, $this->server_ip, $this->server_port);
         socket_write($socket, $message);
         $this->return_text = iconv("big5", "utf-8", socket_read($socket, strlen($message) * 3));
         socket_shutdown($socket);
         socket_close($socket);
     }
     return $this->return_text;
 }
开发者ID:spicyscap,项目名称:CKIPClient-PHP,代码行数:40,代码来源:CKIPClient.php


示例6: connectSocket

 protected function connectSocket()
 {
     if (filter_var($this->host, FILTER_VALIDATE_IP)) {
         $ip = $this->host;
     } else {
         $ip = gethostbyname($this->host);
         if ($ip == $this->host) {
             throw new MongoConnectionException(sprintf('couldn\'t get host info for %s', $this->host));
         }
     }
     // For some reason, PHP doesn't currently allow resources opened with
     // fsockopen/pfsockopen to be used with socket_* functions, but HHVM does.
     if (defined('HHVM_VERSION')) {
         $this->socket = pfsockopen($ip, $this->port, $errno, $errstr, $this->connectTimeoutMS / 1000);
         if ($this->socket === false) {
             $this->socket = null;
             throw new MongoConnectionException(sprintf("unable to connect to {$ip}:{$this->port} because: %s", "{$errstr} ({$errno})"));
         }
     } else {
         $this->socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname("tcp"));
         if (!$this->socket) {
             throw new MongoConnectionException(sprintf('error creating socket: %s', socket_strerror(socket_last_error())));
         }
         $connected = socket_connect($this->socket, $ip, $this->port);
         if (!$connected) {
             throw new MongoConnectionException(sprintf("unable to connect to {$ip}:{$this->port} because: %s", socket_strerror(socket_last_error())));
         }
     }
 }
开发者ID:Wynncraft,项目名称:mongofill,代码行数:29,代码来源:Socket.php


示例7: listen

 /**
  * Começa a escutar conexões e processar as demais funcionalidades
  * @param int $port número da porta
  * @throws EndPointException
  */
 public function listen($port)
 {
     $this->port = $port;
     /* @var resource cria o socket que escutará conexões */
     $this->serverSocket = socket_create(AF_INET, SOCK_STREAM, getprotobyname('TCP'));
     if (!socket_set_option($this->serverSocket, SOL_SOCKET, SO_REUSEADDR, 1)) {
         echo socket_strerror(socket_last_error($this->serverSocket));
         exit;
     }
     /* seta o host e a porta */
     if (!@socket_bind($this->serverSocket, 0, $this->port)) {
         throw new EndPointException("socket_bind() falhou: resposta: " . socket_strerror(socket_last_error($this->serverSocket)));
     }
     /* inicia a escuta de conexões */
     if (!@socket_listen($this->serverSocket)) {
         throw new EndPointException("socket_listen() falhou: resposta: " . socket_strerror(socket_last_error($this->serverSocket)));
     }
     /* cria um array de sockets e adiciona o serverSocket no array */
     $this->sockets = array($this->serverSocket);
     $this->loopPrincipal();
     /* Fecha todos os sockets e encerra a aplicação */
     foreach ($this->sockets as $socket) {
         if (get_resource_type($socket) == "Socket") {
             socket_close($socket);
         }
     }
 }
开发者ID:rubensm1,项目名称:basic,代码行数:32,代码来源:WebSocket.php


示例8: mServer

 public function mServer()
 {
     $sock = socket_create(AF_INET, SOCK_DGRAM, getprotobyname('udp'));
     $mIP = '239.255.255.250';
     if (!socket_bind($sock, $mIP, 1900)) {
         $errorcode = socket_last_error();
         $errormsg = socket_strerror($errorcode);
         die("Could not bind socket : [{$errorcode}] {$errormsg} \n");
     }
     socket_set_option($sock, IPPROTO_IP, MCAST_JOIN_GROUP, array("group" => '239.255.255.250', "interface" => 0));
     while (1) {
         echo "Waiting for data ... \n";
         socket_recvfrom($sock, $buf, 512, 0, $remote_ip, $remote_port);
         echo "{$remote_ip} : {$remote_port} -- " . $buf;
         $query = $this->parseHeaders($buf);
         if (!isset($query["m-search"])) {
             continue;
         }
         $response = "HTTP/1.1 200 OK\r\n";
         $response .= "CACHE-CONTROL: max-age=1810\r\n";
         $response .= "DATE: " . date("r") . "\r\n";
         $response .= "EXT:\r\n";
         $response .= "LOCATION: http://192.168.7.123:9000/TMSDeviceDescription.xml\r\n";
         $response .= "SERVER: Linux/3.x, UPnP/1.1, fheME/0.6\r\n";
         $response .= "ST: urn:fheme.de:service:X_FIT_HomeAutomation:1\r\n";
         $response .= "USN: uuid:f6da16ab-0d1b-fe1c-abca-82aacf4afcac::urn:fheme.de:service:X_FIT_HomeAutomation:1\r\n";
         $response .= "Content-Length: 0\r\n";
         $response .= "\r\n";
         //Send back the data to the client
         socket_sendto($sock, $response, strlen($response), 0, $mIP, $remote_port);
     }
     socket_close($sock);
 }
开发者ID:nemiah,项目名称:fheME,代码行数:33,代码来源:phpUPnP.class.php


示例9: create

 /**
  * 創建SOCKET
  * @author wave
  */
 protected static function create()
 {
     self::$sock = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
     if (!self::$sock) {
         exit('create socket error');
     }
 }
开发者ID:DenonHuang,项目名称:xbphp,代码行数:11,代码来源:Socket.class.php


示例10: initIcecastComm

 function initIcecastComm($serv = '127.0.0.1', $port = 8000, $mount = "/setme", $pass = "hackmake")
 {
     global $iceGenre, $iceName, $iceDesc, $iceUrl, $icePublic, $icePrivate, $iceAudioInfoSamplerate, $iceAudioInfoBitrate, $iceAudioInfoChannels;
     // We're going to create a tcp socket.
     $sock = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
     socket_set_block($sock) or die("Blocking error: " . socket_strerror(socket_last_error($sock)) . " \n");
     if (!$sock) {
         die("Unable to create socket! " . socket_strerror(socket_last_error($sock)) . " \n");
     } else {
         // Connect to the server.
         echo "Connecting to {$serv} on port {$port}\n";
         if (socket_connect($sock, $serv, $port)) {
             echo "Connection established! Sending login....\n";
             $this->sendData($sock, "SOURCE {$mount} HTTP/1.0\r\n");
             $this->sendLogin($sock, $pass);
             $this->sendData($sock, "User-Agent: icecastwebm-php\r\n");
             $this->sendData($sock, "Content-Type: video/webm\r\n");
             $this->sendData($sock, "ice-name: {$iceName}\r\n");
             $this->sendData($sock, "ice-url: {$iceUrl}\r\n");
             $this->sendData($sock, "ice-genre: {$iceGenre}\r\n");
             $this->sendData($sock, "ice-public: {$icePublic}\r\n");
             $this->sendData($sock, "ice-private: {$icePrivate}\r\n");
             $this->sendData($sock, "ice-description: {$iceDesc}\r\n");
             $this->sendData($sock, "ice-audio-info: ice-samplerate={$iceAudioInfoSamplerate};ice-bitrate={$iceAudioInfoBitrate};ice-channels={$iceAudioInfoChannels}\r\n");
             $this->sendData($sock, "\r\n");
             // Go into loop mode.
             $this->parseData($sock);
             $this->initStream($sock);
             // Start the stream.
             //die;
         } else {
             die("Unable to connect to server! " . socket_strerror(socket_last_error($sock)) . " \n");
         }
     }
 }
开发者ID:voice06,项目名称:rtmp2webmicecast,代码行数:35,代码来源:icecastwebm.php


示例11: __construct

 public function __construct($ip, $port)
 {
     $this->IP = $ip;
     $this->Port = $port;
     $this->Socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname("tcp"));
     $this->Connected = false;
     SocketManager::AddSocket($this);
 }
开发者ID:LuscasLeo,项目名称:BlobCms,代码行数:8,代码来源:Socket.php


示例12: SMTP_Server_Socket

 /**
  * Constructor with an optional argument of a socket resource
  *
  * @param resource $socket A socket resource as returned by socket_create() or socket_accept()
  */
 function SMTP_Server_Socket($socket = null)
 {
     $this->log = new SMTP_Server_Log();
     $this->socket = $socket;
     $this->remote_address = '';
     if (!$this->socket) {
         $this->socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
     }
 }
开发者ID:vivek779,项目名称:php-smtp,代码行数:14,代码来源:SMTP_Server_Socket.php


示例13: getConnection

 /**
  * @return resource
  * @throws \Exception
  */
 public function getConnection()
 {
     if (!empty($this->socket)) {
         return $this->socket;
     }
     $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     socket_set_option($this->socket, getprotobyname('TCP'), TCP_NODELAY, 1);
     socket_set_option($this->socket, SOL_SOCKET, SO_RCVTIMEO, ["sec" => self::STREAM_TIMEOUT, "usec" => 0]);
     if (!socket_connect($this->socket, $this->host, $this->port)) {
         throw new ConnectionException("Unable to connect to Cassandra node: {$this->host}:{$this->port}");
     }
     return $this->socket;
 }
开发者ID:locked,项目名称:phpcassandratests,代码行数:17,代码来源:Node.php


示例14: getConnection

 /**
  * 
  * @throws Exception
  * @return resource
  */
 public function getConnection()
 {
     if (!empty($this->socket)) {
         return $this->socket;
     }
     $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     socket_set_option($this->socket, getprotobyname('TCP'), TCP_NODELAY, 1);
     foreach ($this->_options['socket'] as $optname => $optval) {
         socket_set_option($this->socket, SOL_SOCKET, $optname, $optval);
     }
     if (!socket_connect($this->socket, $this->_options['host'], $this->_options['port'])) {
         throw new Exception("Unable to connect to Cassandra node: {$this->_options['host']}:{$this->_options['port']}");
     }
     return $this->socket;
 }
开发者ID:zhgit,项目名称:php-cassandra,代码行数:20,代码来源:Node.php


示例15: Startup

 public function Startup()
 {
     $Host = "10.10.43.138";
     $Proto = getprotobyname("tcp");
     set_time_limit(0);
     $Socket = socket_create(AF_INET, SOCK_STREAM, $Proto) or dir("Create socket failed!!\n");
     socket_bind($Socket, $Host, 5678) or die("Can not bind socket!!\n");
     $Result = socket_listen($Socket);
     while (true) {
         $Client = socket_accept($Socket) or die("Can not read input!!\n");
         $this->ResBind($Client);
         $this->ResUserInfo($Client);
     }
     socket_close($Socket);
     // close server
 }
开发者ID:svn2github,项目名称:ybtx,代码行数:16,代码来源:SimpleServer.php


示例16: read

 public static function read($addr, $proto = 'udp')
 {
     $socket = socket_create(AF_INET, self::$proto[$proto], getprotobyname($proto)) or die('socket create error ' . socket_strerror(socket_last_error()));
     //socket_set_blocking($socket, 0);//0-非阻塞   1-阻塞
     list($host, $port) = explode(':', $addr);
     socket_bind($socket, $host, $port) or die('socket bind error\\n');
     socket_listen($socket, 4) or die('socket listen error\\n');
     while (1) {
         $newsocket = socket_accept($socket) or die('socket accept error\\n');
         //socket_write($newsocket, date('Y-m-d H:i:s'));
         if ($res = socket_read($newsocket, 8192)) {
             //sleep(5);
             var_dump(date('Y-m-d H:i:s'), $res);
         }
     }
 }
开发者ID:akaiidle,项目名称:newborn,代码行数:16,代码来源:socket.php


示例17: connect

 /**
  * 建立链接
  *
  * @return boolean
  */
 public function connect()
 {
     //应该用更合适的方法去判断连接是否已经建立
     if ($this->sock == true) {
         return true;
     }
     $commonProtocol = getprotobyname("tcp");
     $socket = socket_create(AF_INET, SOCK_STREAM, $commonProtocol);
     if (socket_connect($socket, $this->host, $this->port) == false) {
         $this->errno = ERR_REQUEST_CONNECT_FAILED;
         $this->error = "建立连接失败[{$this->host}:{$this->port}]";
         return false;
     }
     $this->sock = $socket;
     return true;
 }
开发者ID:burstas,项目名称:cwinux-mq,代码行数:21,代码来源:CwxRequest.class.php


示例18: __construct

 public function __construct($address = 'localhost', $port = 80)
 {
     ob_implicit_flush();
     $this->socket_master = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
     //socket_set_option($this->socket_master, SOL_SOCKET, SO_REUSEADDR, 1);
     //socket_bind($this->socket_master, $address, $port);
     //echo   socket_strerror(socket_last_error());
     //socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 2, 'usec' => 0));
     $sc = socket_connect($this->socket_master, $address, $port);
     //	socket_listen($this->socket_master);
     //echo   socket_strerror(socket_last_error());
     $this->make_hand_shake($this->socket_master);
     $this->connect($this->socket_master);
     //echo 'WebSocket Client Connected: ' . $address . ':' . $port . PHP_EOL;
     $p = $this->send('ping');
     return $sc && $p != null;
 }
开发者ID:ShaolongHu,项目名称:phoronix-test-suite,代码行数:17,代码来源:pts_web_socket_client.php


示例19: __construct

 /**
  * Constructor.
  *
  * @param string $host
  *   Hostname
  * @param float $timeout
  *   Connect timeout
  * @param float $stream_timeout
  *   Stream timeout
  */
 public function __construct($host, $connect_timeout = 3, $stream_timeout = 10)
 {
     if (strstr($host, ':')) {
         $port = (int) substr(strstr($host, ':'), 1);
         $host = substr($host, 0, -1 - strlen($port));
         if (!$port) {
             throw new InvalidArgumentException('Invalid port number');
         }
     } else {
         $port = 9042;
     }
     $this->connection = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     socket_set_option($this->connection, getprotobyname('TCP'), 1, 1);
     socket_set_option($this->connection, SOL_SOCKET, SO_RCVTIMEO, array("sec" => $stream_timeout, "usec" => 0));
     if (!socket_connect($this->connection, $host, $port)) {
         throw new Exception('Unable to connect to Cassandra node: ');
     }
 }
开发者ID:asimlqt,项目名称:php-cassandra-client,代码行数:28,代码来源:Transport.php


示例20: testConstruct

 /**
  * Test that HttpSocket::__construct does what one would expect it to do
  *
  */
 function testConstruct()
 {
     $this->Socket->reset();
     $baseConfig = $this->Socket->config;
     $this->Socket->expectNever('connect');
     $this->Socket->__construct(array('host' => 'foo-bar'));
     $baseConfig['host'] = 'foo-bar';
     $baseConfig['protocol'] = getprotobyname($baseConfig['protocol']);
     $this->assertIdentical($this->Socket->config, $baseConfig);
     $this->Socket->reset();
     $baseConfig = $this->Socket->config;
     $this->Socket->__construct('http://www.cakephp.org:23/');
     $baseConfig['host'] = 'www.cakephp.org';
     $baseConfig['request']['uri']['host'] = 'www.cakephp.org';
     $baseConfig['port'] = 23;
     $baseConfig['request']['uri']['port'] = 23;
     $baseConfig['protocol'] = getprotobyname($baseConfig['protocol']);
     $this->assertIdentical($this->Socket->config, $baseConfig);
 }
开发者ID:kaz0636,项目名称:openflp,代码行数:23,代码来源:http_socket.test.php



注:本文中的getprotobyname函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP getqtypelist函数代码示例发布时间:2022-05-15
下一篇:
PHP getposttablebytid函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap