当前位置: 首页>>代码示例>>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;未经允许,请勿转载。