/** * @param string $payload * * @return string * @throws ConnectionException */ public function send($payload) { if (!$this->ws->isConnected()) { throw new ConnectionException(sprintf('Could not connect to "%s"', $this->address)); } $this->ws->send($payload); $response = $this->ws->receive(); if (($opCode = $this->ws->getLastOpcode()) !== 'text') { throw new ConnectionException(sprintf('Received non-text frame of type "%s" with text: "%s"', $opCode, $response)); } return $response; }
public function testClose() { // Start a NEW dedicated server for this test $cmd = 'php examples/echoserver.php'; $outputfile = 'build/serveroutput_close.txt'; $pidfile = 'build/server_close.pid'; exec(sprintf("%s > %s 2>&1 & echo \$! >> %s", $cmd, $outputfile, $pidfile)); usleep(500000); $port = trim(file_get_contents($outputfile)); $ws = new Client('ws://localhost:' . $port . '/' . $this->test_id); $ws->send('exit'); $response = $ws->receive(); $this->assertEquals('ttfn', $response); $this->assertEquals(1000, $ws->getCloseStatus()); $this->assertFalse($ws->isConnected()); }