From 79490a0616c0d2330c89358fd1560247453a01f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Fri, 19 Mar 2021 22:59:57 +0100 Subject: [PATCH] MAPG-203 add class for multiplayer internal connection (PHP-NodeJS TCP) --- src/Multi/MultiConnector.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/Multi/MultiConnector.php diff --git a/src/Multi/MultiConnector.php b/src/Multi/MultiConnector.php new file mode 100644 index 0000000..d74535e --- /dev/null +++ b/src/Multi/MultiConnector.php @@ -0,0 +1,24 @@ + $func, + 'args' => $args + ]); + + $connection = fsockopen($_ENV['MULTI_INTERNAL_HOST'], $_ENV['MULTI_INTERNAL_PORT']); + fwrite($connection, $message); + $response = ''; + while (!feof($connection)) { + $response .= fgets($connection); + } + fclose($connection); + + if ($response !== 'OK') { + throw new \Exception('Sending message failed with response: ' . $response); + } + } +}