/** * Prepares a new WebSocket server on a specified host & port. * * @param string $tcpid * * @return YnievesDotNet\FourStream\FourStream\FourStreamServer */ public function start($tcpid) { $oldNode = FSNode::all(); echo "Closing old nodes", "\n"; foreach ($oldNode as $node) { $node->delete(); } $this->server = new Websocket(new Socket($tcpid)); $this->server->on('open', function (Bucket $bucket) { Event::fire(new Events\ConnectionOpen($bucket)); }); $this->server->on('message', function (Bucket $bucket) { Event::fire(new Events\MessageReceived($bucket)); }); $this->server->on('binary-message', function (Bucket $bucket) { Event::fire(new Events\BinaryMessageReceived($bucket)); }); $this->server->on('ping', function (Bucket $bucket) { Event::fire(new Events\PingReceived($bucket)); }); $this->server->on('error', function (Bucket $bucket) { Event::fire(new Events\ErrorGenerated($bucket)); }); $this->server->on('close', function (Bucket $bucket) { Event::fire(new Events\ConnectionClose($bucket)); }); return $this; }