當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ConnectionInterface::close方法代碼示例

本文整理匯總了PHP中Ratchet\ConnectionInterface::close方法的典型用法代碼示例。如果您正苦於以下問題:PHP ConnectionInterface::close方法的具體用法?PHP ConnectionInterface::close怎麽用?PHP ConnectionInterface::close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Ratchet\ConnectionInterface的用法示例。


在下文中一共展示了ConnectionInterface::close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: onOpen

 public function onOpen(ConnectionInterface $from, RequestInterface $request = null)
 {
     echo "New HTTP connection!\n";
     //Variables in URLs are not supported in Ratchet for now
     //See https://github.com/cboden/Ratchet/pull/143
     $requestPath = $request->getPath();
     $pathParts = explode('/', preg_replace('#^/peerjs/#', '', $requestPath));
     //Remove /peerjs
     $action = array_pop($pathParts);
     $peerToken = array_pop($pathParts);
     $peerId = array_pop($pathParts);
     $key = array_pop($pathParts);
     $respStatus = 200;
     $respHeaders = array('X-Powered-By' => \Ratchet\VERSION, 'Access-Control-Allow-Origin' => '*');
     $respBody = null;
     switch ($action) {
         case 'id':
             $respHeaders['Content-Type'] = 'text/html';
             if ($peerId === null) {
                 do {
                     $peerId = substr(sha1(uniqid('', true) . mt_rand()), 0, self::PEERID_LENGTH);
                 } while ($this->peerServer->peerIdExists($peerId));
             }
             $respBody = $peerId;
             break;
         case 'peers':
             if (self::ALLOW_DISCOVERY) {
                 $peers = $this->peerServer->listPeers();
                 $list = array();
                 foreach ($peers as $peer) {
                     $list[] = $peer['id'];
                 }
                 $respBody = $list;
             } else {
                 $respStatus = 401;
                 // Access denied
             }
             break;
         case 'offer':
         case 'candidate':
         case 'answer':
         case 'leave':
             //TODO: start streaming?
         //TODO: start streaming?
         default:
             $respStatus = 400;
             //Bad request
     }
     if (is_array($respBody)) {
         // Encode to JSON
         $respHeaders['Content-Type'] = 'application/json';
         $respBody = json_encode($respBody);
     }
     //Send response
     $response = new Response($respStatus, $respHeaders, (string) $respBody);
     $from->send((string) $response);
     $from->close();
 }
開發者ID:mtobbias,項目名稱:GuaranaOS,代碼行數:58,代碼來源:PeerHttpServer.class.php

示例2: onOpen

 /**
  * @param \Ratchet\ConnectionInterface $conn
  * @param \Guzzle\Http\Message\RequestInterface $request null is default because PHP won't let me overload; don't pass null!!!
  * @throws \UnexpectedValueException if a RequestInterface is not passed
  */
 public function onOpen(ConnectionInterface $conn, \Guzzle\Http\Message\RequestInterface $request = null)
 {
     $response = new \Guzzle\Http\Message\Response(200);
     $response->setBody(file_get_contents($this->path));
     $conn->send($response);
     $conn->close();
 }
開發者ID:calcinai,項目名稱:phpi-websocket,代碼行數:12,代碼來源:ForExampleOnlyHTTPServer.php

示例3: onOpen

 final function onOpen(ConnectionInterface $conn, GuzzleRequest $request = null)
 {
     $this->onRequest($request);
     $userData = $this->session->get('user');
     if (count($userData) == 2 && is_int($userData[0])) {
         $userId = $userData[0];
         $userRole = $userData[1];
         $this->securityProvider->setRole($userData[1]);
         if ($this->securityProvider->isGranted($this->expectedRole)) {
             $actionRequest = new Request($request, $userId);
             $response = call_user_func($this->callback, $actionRequest);
         } else {
             $response = new Response('ACCESS DENIED', Response::HTTP_FORBIDDEN);
         }
         $conn->send((string) $response);
     }
     $conn->close();
 }
開發者ID:elfchat,項目名稱:elfchat,代碼行數:18,代碼來源:Action.php

示例4: onOpen

 public function onOpen(WebSocketConnection $connection)
 {
     if (count($this->connections) > 100) {
         $connection->close();
         return;
     }
     $this->connections->pushBack($connection);
 }
開發者ID:proof,項目名稱:blackjack-php-server,代碼行數:8,代碼來源:WebSocketManager.php

示例5: onError

 public function onError(ConnectionInterface $con, \Exception $ex)
 {
     // TODO: Log error
     try {
         try {
             if ($this->clients[$con->resourceId]) {
                 $this->clients[$con->resourceId]->endGame();
             }
         } catch (Exception $ex) {
             /* Logic might not exist anymore */
         }
         $con->close();
     } catch (Exception $ex) {
         /* Connection may already be closed */
     }
 }
開發者ID:BradlySharpe,項目名稱:Digimon-v3,代碼行數:16,代碼來源:WebSocket.php

示例6: onMessage

 function onMessage(ConnectionInterface $from, $msg)
 {
     $msg = explode(' ', $msg);
     $msg[0] = 'pong';
     $from->send(implode(' ', $msg));
     $from->close();
 }
開發者ID:fencer-md,項目名稱:stoticlle,代碼行數:7,代碼來源:AnnouncementsServerStatus.php

示例7: serve

 public function serve(ConnectionInterface $conn, RequestInterface $request = null, array $parameters)
 {
     try {
         $application = $this->applications->get($parameters['application']);
         $conn->send((string) $application->execute($parameters['module'], $request));
         $conn->close();
     } catch (ApplicationNotFoundException $e) {
         $response = new Response(404, null, $e->getMessage());
         $conn->send((string) $response);
         $conn->close();
     } catch (\Exception $e) {
         $response = new Response(500, null, $e->getMessage());
         $conn->send((string) $response);
         $conn->close();
     }
 }
開發者ID:owlycode,項目名稱:reactboard,代碼行數:16,代碼來源:ApplicationServer.php

示例8: onError

 public function onError(ConnectionInterface $conn, \Exception $e)
 {
     unset($conn->handler);
     $conn->close();
 }
開發者ID:igez,項目名稱:gaiaehr,代碼行數:5,代碼來源:HL7ServerAbstract.php

示例9: onOpen

 /**
  * {@inheritdoc}
  */
 function onOpen(ConnectionInterface $conn)
 {
     if ($this->isBlocked($conn->remoteAddress)) {
         return $conn->close();
     }
     return $this->_decorating->onOpen($conn);
 }
開發者ID:netconstructor,項目名稱:Ratchet,代碼行數:10,代碼來源:IpBlackList.php

示例10: onError

 /**
  * If we have an error.
  *
  * @param ConnectionInterface $conn
  *
  * @param \Exception $e
  */
 public function onError(ConnectionInterface $conn, \Exception $e)
 {
     /**
      * Close the con on error.
      */
     $conn->close();
 }
開發者ID:CrashfortStudios,項目名稱:Chat,代碼行數:14,代碼來源:ChatManager.php

示例11: onError

 public function onError(ConnectionInterface $client, \Exception $e)
 {
     echo "Erreur: ({$client->resourceId}) " . $e->getMessage() . PHP_EOL;
     $client->close();
 }
開發者ID:hidrarga,項目名稱:chatbox,代碼行數:5,代碼來源:Chat.php

示例12: onOpen

 public function onOpen(ConnectionInterface $from, RequestInterface $request = null)
 {
     if (empty($request)) {
         $resp = new Response(400);
         $from->send((string) $resp);
         $from->close();
         return;
     }
     // Session management
     $saveHandler = $this->_handler;
     $id = $request->getCookie(ini_get('session.name'));
     if (empty($id)) {
         $id = sha1(uniqid() . mt_rand());
     }
     // Crappy workaround for sessions - don't know why they are not saved
     // @see https://github.com/ratchetphp/Ratchet/blob/master/src/Ratchet/Session/SessionProvider.php
     if (isset($this->sessions[$id])) {
         $from->Session = $this->sessions[$id];
     } else {
         $from->Session = new Session(new VirtualSessionStorage($saveHandler, $id, $this->_serializer));
         $this->sessions[$id] = $from->Session;
     }
     if (ini_get('session.auto_start')) {
         $from->Session->start();
     }
     $this->onRequest($from, $request);
 }
開發者ID:Rudi9719,項目名稱:stein-syn,代碼行數:27,代碼來源:HttpServer.class.php

示例13: openConnection

 /**
  * Triggered on connection, populates the connection with a consumer.
  *
  * @param Conn $conn
  *
  * @return TopicsManager
  */
 public function openConnection(Conn $conn)
 {
     try {
         $conn->User = $this->consumerManager->create($conn->Session);
     } catch (\RuntimeException $e) {
         $conn->close();
     }
     return $this;
 }
開發者ID:nlegoff,項目名稱:Phraseanet,代碼行數:16,代碼來源:TopicsManager.php

示例14: serve

 public function serve(ConnectionInterface $conn, RequestInterface $request = null, array $parameters)
 {
     try {
         $path = $this->assets->get($parameters['asset'])->getFullPath();
         if (!file_exists($path)) {
             throw new FileNotFoundException($path);
         }
         $response = new Response(200, array('Content-Type' => Mimetypes::getInstance()->fromFilename($path)), file_get_contents($path));
         $conn->send((string) $response);
         $conn->close();
     } catch (AssetNotFoundException $e) {
         $response = new Response(404, null, '');
         $conn->send((string) $response);
         $conn->close();
     } catch (FileNotFoundException $e) {
         $response = new Response(404, null, '');
         $conn->send((string) $response);
         $conn->close();
     } catch (\Exception $e) {
         $response = new Response(500, null, '');
         $conn->send((string) $response);
         $conn->close();
     }
 }
開發者ID:owlycode,項目名稱:reactboard,代碼行數:24,代碼來源:AssetServer.php

示例15: onOpen

 public function onOpen(ConnectionInterface $from, RequestInterface $request = null)
 {
     echo "New HTTP connection!\n";
     //Variables in URLs are not supported in Ratchet for now
     //See https://github.com/cboden/Ratchet/pull/143
     $requestPath = $request->getPath();
     $pathParts = explode('/', preg_replace('#^/peerjs/#', '', $requestPath));
     //Remove /peerjs
     $action = array_pop($pathParts);
     $peerToken = array_pop($pathParts);
     $peerId = array_pop($pathParts);
     $key = array_pop($pathParts);
     $respStatus = 200;
     $respHeaders = array('X-Powered-By' => \Ratchet\VERSION, 'Access-Control-Allow-Origin' => '*');
     $respBody = null;
     switch ($action) {
         case 'id':
             $respHeaders['Content-Type'] = 'text/html';
             if ($peerId === null) {
                 do {
                     $peerId = sha1(uniqid('', true) . mt_rand());
                 } while ($this->peerServer->peerIdExists($peerId));
             }
             $respBody = $peerId;
             break;
         case 'offer':
         case 'candidate':
         case 'answer':
         case 'leave':
             //TODO: start streaming?
         //TODO: start streaming?
         default:
             $respStatus = 400;
             //Bad request
     }
     //Send response
     $response = new Response($respStatus, $respHeaders, (string) $respBody);
     $from->send((string) $response);
     $from->close();
 }
開發者ID:CanaimaGNULinux,項目名稱:Canaima-Tour,代碼行數:40,代碼來源:PeerHttpServer.class.php


注:本文中的Ratchet\ConnectionInterface::close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。