PHP Fatal error: Uncaught exception 'React\Socket\ConnectionException' with message 'Could not bind to tcp://0.0.0.0:80: Address already in use' in /websocket/vendor/react/socket/React/Socket/Server.php:23 $loop = Factory::create();
// Setup our Ratchet ChatRoom application $webSock = new Reactor($loop); $webSock->listen(80, '0.0.0.0'); $webSock->listen(8080, '0.0.0.0'); $webServer = new IoServer( // Basic I/O with clients, new WsServer( // WebSockets new ServerProtocol( // WAMP new wampserver ) ) , $webSock );
// Allow Flash sockets (Internet Explorer) to connect to our app $flashSock = new Reactor($loop); $flashSock->listen(843, '0.0.0.0'); $policy = new FlashPolicy; $policy->addAllowedAccess('*', 80); $policy->addAllowedAccess('*', 8080); $policy->addAllowedAccess('*', 443); $webServer = new IoServer($policy, $flashSock);
// Start Event Loop $loop->run();
$loop = Factory::create();
$webSock = new Reactor($loop); $webSock->listen(80, '0.0.0.0'); $webSock->listen(8080, '0.0.0.0'); $webSock->listen(843, '0.0.0.0'); $router = new wampserverRouter; $webServer = new IoServer($router, $webSock);<?phpnamespace Ratchet\Website;use Ratchet\MessageComponentInterface;use Ratchet\ConnectionInterface;use Ratchet\Server\FlashPolicy;
use Ratchet\WebSocket\WsServer;use Ratchet\Wamp\ServerProtocol;use Ratchet\Website\wampserver;
class wampserverRouter implements MessageComponentInterface { private $policy; private $wamp;
public function __construct() { //Setup Flash Server $this->policy = new FlashPolicy; $this->policy->addAllowedAccess('*', 80); $this->policy->addAllowedAccess('*', 8080); $this->policy->addAllowedAccess('*', 443); //Setup Wamp Server $this->wamp = new WsServer( // WebSockets new ServerProtocol( // WAMP new wampserver ) ); }
public function onOpen(ConnectionInterface $conn){ //Set default route to the wamp server $conn->route = $this->wamp; $conn->route->onOpen($conn); //Set first message to true $conn->firstMessage = true; }
public function onMessage(ConnectionInterface $from, $msg) { //If first message is true check if we have a policy file request if($from->firstMessage){ $from->firstMessage = false; $flashPolicyRequest = strpos($msg, 'policy-file-request'); if ($flashPolicyRequest !== false) {
//Send an onclose to websocket class $from->route->onClose($from);
//Change route to flash policy $from->route = $this->policy; } } $from->route->onMessage($from, $msg); }
public function onClose(ConnectionInterface $conn){ if (isset($conn->route)){ $conn->route->onClose($conn); } }
public function onError(ConnectionInterface $conn, \Exception $e) { $conn->route->onError($conn, $e); }}