本文整理汇总了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();
}
示例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();
}
示例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();
}
示例4: onOpen
public function onOpen(WebSocketConnection $connection)
{
if (count($this->connections) > 100) {
$connection->close();
return;
}
$this->connections->pushBack($connection);
}
示例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 */
}
}
示例6: onMessage
function onMessage(ConnectionInterface $from, $msg)
{
$msg = explode(' ', $msg);
$msg[0] = 'pong';
$from->send(implode(' ', $msg));
$from->close();
}
示例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();
}
}
示例8: onError
public function onError(ConnectionInterface $conn, \Exception $e)
{
unset($conn->handler);
$conn->close();
}
示例9: onOpen
/**
* {@inheritdoc}
*/
function onOpen(ConnectionInterface $conn)
{
if ($this->isBlocked($conn->remoteAddress)) {
return $conn->close();
}
return $this->_decorating->onOpen($conn);
}
示例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();
}
示例11: onError
public function onError(ConnectionInterface $client, \Exception $e)
{
echo "Erreur: ({$client->resourceId}) " . $e->getMessage() . PHP_EOL;
$client->close();
}
示例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);
}
示例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;
}
示例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();
}
}
示例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();
}