teddy/websockets

帮助使用websockets

dev-master 2016-05-15 16:34 UTC

This package is not auto-updated.

Last update: 2024-09-20 21:36:27 UTC


README

扩展,帮助使用WebSockets

用法

composer require teddy/websockets

复制websockets.js文件,覆盖Controller,添加/bin/server.php,运行/bin/server.php

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;

require dirname(__DIR__) . '/vendor/autoload.php';

$rootDir = __DIR__ . '/..';

$params = [
	'wwwDir' => $rootDir . '/www',
	'appDir' => $rootDir . '/app',
	'tempDir' => $rootDir . '/temp',
	'testMode' => TRUE
];
$configurator = (new Nette\Configurator($params))
	->addConfig(__DIR__ . '/config.neon')
	->setDebugMode(TRUE);
$configurator->createRobotLoader()
	->addDirectory(__DIR__ . '/../app')
	->register();
$container = $configurator->createContainer();

$server = IoServer::factory(
	new HttpServer(
		new WsServer(
			new \Teddy\WebSockets\Controller($container) // you should override this class
		)
	),
	8080
);

$server->run();

必须创建子域名wss.domain.tld,因为否则SSL无法工作。http://grezcz.tumblr.com/post/143320629816/rozchozen%C3%AB-ratchetu-na-ssl(检查是否不会破坏HTTP o_O)