public function establishConnection($data) { $this->_transport = WebSocketTransportFactory::fromSocketData($this, $data, $this->logger); $myself = $this; $this->_transport->on("handshake", function (Handshake $request) use($myself) { $myself->emit("handshake", array($request)); }); $this->_transport->on("connect", function () use($myself) { $myself->emit("connect", array($myself)); }); $this->_transport->on("message", function ($message) use($myself) { $myself->emit("message", array("message" => $message)); }); $this->_transport->on("flashXmlRequest", function ($message) use($myself) { $myself->emit("flashXmlRequest"); }); if ($this->_transport instanceof WebSocketTransportFlash) { return; } $request = Request::fromString($data); $this->_transport->respondTo($request); }