<?phpnamespace App\Net;use Evenement\EventEmitter;use JumPHP\Net\Tcp;use JumPHP\Net\TcpConnection;/** * A Link over $engine->tcp(): a plain socket on the desktop, the playground's TCP bridge in the browser * (the application must be approved for TCP by the administrator, docs/tcp.md). */final class TcpLink extends EventEmitter implements Link{ private TcpConnection $connection; public function __construct(Tcp $tcp, string $host, int $port) { $this->connection = $tcp->connect($host, $port); foreach (['open', 'data', 'close', 'error'] as $event) { $this->connection->on($event, fn (...$args) => $this->emit($event, $args)); } } public function write(string $bytes): void { $this->connection->write($bytes); } public function close(): void { $this->connection->close(); }}