當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。