/** * @param $type * @param $data * @param $node_id */ public function send($type, $data, $node_id = null) { $msg = array('type' => $type, 'data' => $data, 'node_id' => $node_id); $host = config('fourstream.host'); $port = config('fourstream.port'); $tcpid = "tcp://{$host}:{$port}"; $client = new WsClient(new SClient($tcpid)); $client->connect(); $client->send(json_encode($msg)); $client->close(); }
/** * The entry method. * * @return int */ public function main() { $server = '127.0.0.1:8889'; while (false !== ($c = $this->getOption($v))) { switch ($c) { case 's': $server = $v; break; case 'h': case '?': return $this->usage(); case '__ambiguous': $this->resolveOptionAmbiguity($v); break; } } $readline = new Console\Readline(); $client = new Websocket\Client(new Socket\Client('tcp://' . $server)); $client->setHost('localhost'); $client->connect(); do { $line = $readline->readLine('> '); if (false === $line || 'quit' === $line) { break; } $client->send($line); } while (true); $client->close(); return; }