当前位置: 首页>>代码示例>>PHP>>正文


PHP stream_socket_recvfrom函数代码示例

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


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


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