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

PHP stream_socket_recvfrom函数代码示例

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

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



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

示例1: run

 public function run($force = false)
 {
     if ($force) {
         $this->killProgramsOnDreddPort();
     }
     $socket = sprintf('tcp://%s:%s', $this->host, $this->port);
     $server = stream_socket_server($socket, $errno, $errorMessage);
     if ($server === false) {
         throw new UnexpectedValueException("Server could not bind to socket: {$errorMessage}");
     }
     $buffer = "";
     for (;;) {
         $client = stream_socket_accept($server);
         while ($socketData = stream_socket_recvfrom($client, self::RECV_LENGTH)) {
             $buffer .= $socketData;
             // determine if message terminating character is present.
             if (strpos($buffer, self::MESSAGE_END) === false) {
                 continue;
             }
             $messages = [];
             foreach (explode(self::MESSAGE_END, $buffer) as $data) {
                 $message = json_decode($data);
                 // if not valid json the partial message needs saved
                 if (!$message) {
                     $buffer = $message;
                     continue;
                 }
                 $messages[] = $message;
             }
             foreach ($messages as $message) {
                 $this->processMessage($message, $client);
             }
         }
     }
 }
开发者ID:ddelnano,项目名称:dredd-hooks-php,代码行数:35,代码来源:Server.php


示例2: sw_server_handle_recvfrom

function sw_server_handle_recvfrom($server_socket, $events, $server)
{
    $data = stream_socket_recvfrom($server_socket, $server->buffer_size, $server->flags, $peer);
    if ($data !== false && $data != '') {
        $server->protocol->onData($peer, $data);
    }
}
开发者ID:jasonshaw,项目名称:framework-1,代码行数:7,代码来源:EventUDP.php


示例3: read

 /**
  * {@inheritdoc}
  */
 public function read($length)
 {
     if (!$this->isReadable()) {
         throw new RuntimeException("Stream is not readable");
     }
     return stream_socket_recvfrom($this->getContext(), $length);
 }
开发者ID:Talesoft,项目名称:tale-net,代码行数:10,代码来源:SocketBase.php


示例4: query

    public function query($text)
    {
        $head = <<<_HEADER_
<?xml version="1.0" ?>
<wordsegmentation version="0.1">
<option showcategory="1" />
<authentication username="{$this->user}" password="{$this->passwd}" />
<text>
_HEADER_;
        $footer = <<<_FOOT_
</text>
</wordsegmentation>
_FOOT_;
        $this->data_send = $text;
        $text = str_replace("&", " ", $text);
        $querystr = $head . $text . $footer;
        $tempxml = simplexml_load_string($querystr);
        $resp = array();
        if ($tempxml) {
            if (stream_socket_sendto($this->sock, $tempxml->asXML())) {
                do {
                    $ttt = stream_socket_recvfrom($this->sock, 65525);
                    $ttt = iconv('big5', 'utf-8', $ttt);
                    $resp[] = $ttt;
                } while (!simplexml_load_string(implode($resp)));
                return $this->data_recv = html_entity_decode(implode($resp));
            }
        } else {
            $this->data_recv = 0;
            return null;
        }
    }
开发者ID:balduran,项目名称:CKIP-interface-for-PHP,代码行数:32,代码来源:CKIP.php


示例5: enableCrypto

 /**
  * {@inheritdoc}
  */
 public function enableCrypto(int $method, float $timeout = 0) : \Generator
 {
     $resource = $this->getResource();
     if ($method & 1 || 0 === $method) {
         yield from $this->await($timeout);
     } else {
         yield from $this->poll($timeout);
         $raw = stream_socket_recvfrom($resource, 11, STREAM_PEEK);
         if (11 > strlen($raw)) {
             throw new FailureException('Failed to read crypto handshake.');
         }
         $data = unpack('ctype/nversion/nlength/Nembed/nmax-version', $raw);
         if (0x16 !== $data['type']) {
             throw new FailureException('Invalid crypto handshake.');
         }
         $version = $this->selectCryptoVersion($data['max-version']);
         if ($method & $version) {
             // Check if version was available in $method.
             $method = $version;
         }
     }
     do {
         // Error reporting suppressed since stream_socket_enable_crypto() emits E_WARNING on failure.
         $result = @stream_socket_enable_crypto($resource, (bool) $method, $method);
     } while (0 === $result && !(yield from $this->poll($timeout)));
     if ($result) {
         $this->crypto = $method;
         return;
     }
     $message = 'Failed to enable crypto.';
     if ($error = error_get_last()) {
         $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
     }
     throw new FailureException($message);
 }
开发者ID:icicleio,项目名称:socket,代码行数:38,代码来源:NetworkSocket.php


示例6: send

 public function send($socket)
 {
     $deferred = new Deferred();
     stream_set_blocking($socket, false);
     $data = $this->getRequest();
     \Amp\onWritable($socket, function ($writer, $socket) use($deferred, &$data) {
         if ($bytes = fwrite($socket, $data)) {
             if ($bytes < \strlen($data)) {
                 $data = substr($data, $bytes);
                 return;
             }
             $size = 8192;
             \Amp\onReadable($socket, function ($reader, $socket) use($deferred, &$size) {
                 /* make attention to not read too much data */
                 $data = stream_socket_recvfrom($socket, $size, STREAM_PEEK);
                 if (false === ($pos = strpos($data, "\r\n\r\n"))) {
                     if (\strlen($data) == $size) {
                         $size *= 2;
                         // unbounded??
                     }
                     return;
                 }
                 \Amp\cancel($reader);
                 $deferred->succeed($this->parseResponse(fread($socket, $pos + 4)));
             });
         } else {
             $deferred->succeed(null);
         }
         \Amp\cancel($writer);
     });
     return $deferred->promise();
 }
开发者ID:lt,项目名称:websocket,代码行数:32,代码来源:Handshake.php


示例7: testThrowsExceptionOnProtocolDesynchronizationErrors

 /**
  * @medium
  * @group connected
  * @expectedException \Predis\Protocol\ProtocolException
  */
 public function testThrowsExceptionOnProtocolDesynchronizationErrors()
 {
     $connection = $this->createConnection();
     $stream = $connection->getResource();
     $connection->writeRequest($this->getCurrentProfile()->createCommand('ping'));
     stream_socket_recvfrom($stream, 1);
     $connection->read();
 }
开发者ID:pikniktech,项目名称:dailybriefweb2,代码行数:13,代码来源:PhpiredisStreamConnectionTest.php


示例8: handleData

 public function handleData($stream)
 {
     $data = stream_socket_recvfrom($stream, $this->bufferSize);
     if ('' === $data || false === $data || feof($stream)) {
         $this->end();
     } else {
         $this->emit('data', array($data, $this));
     }
 }
开发者ID:alexMaluco,项目名称:LightTable-PHP,代码行数:9,代码来源:Connection.php


示例9: read

 /** {@inheritdoc} */
 public function read(FramePickerInterface $picker, Context $context, $isOutOfBand)
 {
     stream_socket_recvfrom($this->socket->getStreamResource(), self::SOCKET_BUFFER_SIZE, STREAM_PEEK, $remoteAddress);
     if (!$remoteAddress && !$this->isLocalIo) {
         stream_socket_recvfrom($this->socket->getStreamResource(), self::SOCKET_BUFFER_SIZE);
         throw new AcceptException($this->socket, 'Can not accept client: failed to receive remote address.');
     }
     $reader = new DatagramClientIo($this->socket, $this->isLocalIo ? null : $remoteAddress);
     return new AcceptedFrame($remoteAddress, new UdpClientSocket($this->socket, $remoteAddress, $reader->read(new RawFramePicker(), $context, $isOutOfBand)));
 }
开发者ID:edefimov,项目名称:async-sockets,代码行数:11,代码来源:DatagramServerIo.php


示例10: handleData

 public function handleData($socket)
 {
     $data = @stream_socket_recvfrom($socket, $this->bufferSize);
     if ('' === $data || false === $data) {
         $this->handleDisconnect($socket);
         $this->loop->removeStream($socket);
     } else {
         $client = $this->getClient($socket);
         $client->emit('data', array($data));
     }
 }
开发者ID:romainneutron,项目名称:SocketServer,代码行数:11,代码来源:Server.php


示例11: handleRecv

 function handleRecv($sock)
 {
     $pkt = stream_socket_recvfrom($sock, self::MAX_PACKET_SIZE, 0, $peer);
     if ($pkt == false) {
         $this->emit('error', array("Reading packet from {$peer} failed"));
         return;
     }
     if ($pkt != "") {
         $this->emit('packet', array($pkt, $peer, $this));
     }
 }
开发者ID:hanlicun,项目名称:PhpCoap,代码行数:11,代码来源:PacketStream.php


示例12: process

 function process()
 {
     $request = stream_socket_recvfrom($this->srv, 1500, 0, $this->cli);
     if ($request == false) {
         cy_log(CYE_ERROR, "read request from srv fd error.");
         return false;
     }
     $this->request_init();
     $this->request($request);
     $this->request_shutdown();
 }
开发者ID:xiaoyjy,项目名称:retry,代码行数:11,代码来源:hb.php


示例13: read

 public function read($stream)
 {
     // Socket is raw, not using fread as it's interceptable by filters
     // See issues #192, #209, and #240
     $data = stream_socket_recvfrom($stream, $this->bufferSize);
     if ('' !== $data && false !== $data) {
         $this->notifyNext(new StreamEvent("/stream/data", $data));
     }
     if ('' === $data || false === $data || !is_resource($stream) || feof($stream)) {
         $this->notifyCompleted();
     }
 }
开发者ID:domraider,项目名称:rxnet,代码行数:12,代码来源:Connection.php


示例14: server

 public function server()
 {
     $socket = stream_socket_server("tcp://127.0.0.1:8000", $errno, $errstr, STREAM_SERVER_BIND);
     if (!$socket) {
         die("{$errstr} ({$errno})");
     }
     do {
         $pkt = stream_socket_recvfrom($socket, 1, 0, $peer);
         echo $pkt, "\n";
         echo "{$peer}\n";
         //stream_socket_sendto($socket, date("D M j H:i:s Y\r\n"), 0, $peer);
     } while (true);
 }
开发者ID:Rgss,项目名称:imp,代码行数:13,代码来源:TestController.php


示例15: read

 public function read()
 {
     $data = stream_socket_recvfrom($this->socket, $this->bufferSize, 0, $peerAddress);
     if ($data === false) {
         // receiving data failed => remote side rejected one of our packets
         // due to the nature of UDP, there's no way to tell which one exactly
         // $peer is not filled either
         $this->notifyError(new \Exception('Invalid message'));
         return;
     }
     $this->notifyNext(new StreamEvent("/datagram/data", $data, ["peer" => $peerAddress]));
     $this->close();
 }
开发者ID:domraider,项目名称:rxnet,代码行数:13,代码来源:Datagram.php


示例16: accept

 /**
  * Accept a connection
  *
  * @return bool|mixed
  */
 public function accept()
 {
     if (($client = stream_socket_accept($this->socket)) === false) {
         // @codeCoverageIgnoreStart
         return false;
         // @codeCoverageIgnoreEnd
     }
     $data = '';
     while (($buf = stream_socket_recvfrom($client, 1024)) !== '') {
         $data .= $buf;
     }
     fclose($client);
     return unserialize($data);
 }
开发者ID:kidaa,项目名称:Parallel.php,代码行数:19,代码来源:Server.php


示例17: server_loop

 function server_loop()
 {
     while (true) {
         $data = '';
         while (true) {
             $buf = stream_socket_recvfrom($this->server_sock, $this->buffer_size, 0, $peer);
             $data .= $buf;
             if ($buf === null or strlen($buf) < $this->buffer_size) {
                 break;
             }
         }
         $this->protocol->onData($peer, $data);
     }
 }
开发者ID:kilmas,项目名称:framework,代码行数:14,代码来源:BlockUDP.php


示例18: readRawDataIntoPicker

 /** {@inheritdoc} */
 protected function readRawDataIntoPicker(FramePickerInterface $picker, $isOutOfBand)
 {
     $size = self::SOCKET_BUFFER_SIZE;
     $resource = $this->socket->getStreamResource();
     do {
         $data = stream_socket_recvfrom($resource, $size, STREAM_PEEK);
         if (strlen($data) < $size) {
             break;
         }
         $size += $size;
     } while (true);
     $data = stream_socket_recvfrom($resource, $size, 0, $actualRemoteAddress);
     return $picker->pickUpData($data, $actualRemoteAddress);
 }
开发者ID:edefimov,项目名称:async-sockets,代码行数:15,代码来源:DatagramClientIo.php


示例19: on

 /**
   Bi-directional UDP communication
   @param $msg the message
   @param $port integer port
   @return the response or an empty string
 
   Whatever program is listening on the other
   end cannot respond on the same port. It must
   send the response on (port+1).
 */
 public static function udpPoke($msg, $port = 9450)
 {
     $socket = stream_socket_server("udp://127.0.0.1:" . ($port + 1), $errno, $errstr, STREAM_SERVER_BIND);
     self::udpSend($msg, $port);
     $read = array($socket);
     $write = null;
     $except = null;
     $ready = stream_select($read, $write, $except, 0, 500);
     $buf = "";
     if ($ready > 0) {
         $buf = stream_socket_recvfrom($socket, 1024, 0, $peer);
     }
     stream_socket_shutdown($socket, STREAM_SHUT_RDWR);
     return $buf;
 }
开发者ID:phpsmith,项目名称:IS4C,代码行数:25,代码来源:UdpComm.php


示例20: run

 function run()
 {
     unlink(__DIR__ . '/alloc.log');
     unlink(__DIR__ . '/free.log');
     $socket = stream_socket_server("udp://127.0.0.1:9999", $errno, $errstr, STREAM_SERVER_BIND);
     if (!$socket) {
         die("{$errstr} ({$errno})");
     }
     while (1) {
         $pkt = stream_socket_recvfrom($socket, 65535, 0, $peer);
         $this->package_decode($pkt);
         //echo "$peer: $pkt\n";
         //stream_socket_sendto($socket, date("D M j H:i:s Y\r\n"), 0, $peer);
     }
 }
开发者ID:pangudashu,项目名称:swoole-src,代码行数:15,代码来源:debug_server.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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