ws works for testing
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Ratchet\MessageComponentInterface;
|
||||
use Ratchet\ConnectionInterface;
|
||||
use Ratchet\Server\IoServer;
|
||||
use Ratchet\Http\HttpServer;
|
||||
use Ratchet\WebSocket\WsServer;
|
||||
|
||||
class TestServer implements MessageComponentInterface
|
||||
{
|
||||
|
||||
public function onOpen(ConnectionInterface $conn): void
|
||||
{
|
||||
$conn->send('Hello World!');
|
||||
echo "New connection: {$conn->resourceId}\n";
|
||||
}
|
||||
|
||||
public function onMessage(ConnectionInterface $from, $msg): void
|
||||
{
|
||||
$from->send("You said: $msg");
|
||||
}
|
||||
|
||||
public function onClose(ConnectionInterface $conn): void
|
||||
{
|
||||
echo "Connection {$conn->resourceId} closed\n";
|
||||
}
|
||||
|
||||
public function onError(ConnectionInterface $conn, \Exception $e): void
|
||||
{
|
||||
echo "Error: {$e->getMessage()}\n";
|
||||
$conn->close();
|
||||
}
|
||||
}
|
||||
|
||||
$server = IoServer::factory(
|
||||
new HttpServer(new WsServer(new TestServer())),
|
||||
8080
|
||||
);
|
||||
|
||||
echo "WebSocket server running on ws://localhost:8080\n";
|
||||
|
||||
$server->run();
|
||||
Reference in New Issue
Block a user