From ffa7c6f5c007dfc826aef0ca27d23bb69bbeed7e Mon Sep 17 00:00:00 2001
From: Fibinger Ádám <adam.fibinger@wup.hu>
Date: Thu, 04 Jun 2020 23:10:08 +0200
Subject: [PATCH] BO pöttyök + BestOf kupa típus

---
 ws-com/src/Chat.php |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/ws-com/src/Chat.php b/ws-com/src/Chat.php
new file mode 100644
index 0000000..1fefdff
--- /dev/null
+++ b/ws-com/src/Chat.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace WS;
+
+use Ratchet\MessageComponentInterface;
+use Ratchet\ConnectionInterface;
+
+class Chat implements MessageComponentInterface
+{
+	protected $clients;
+
+	public function __construct()
+	{
+		$this->clients = new \SplObjectStorage;
+	}
+
+	public function onOpen(ConnectionInterface $conn)
+	{
+		$this->clients->attach($conn);
+		$conn->send("Hello overlay client!");
+	}
+
+	public function onMessage(ConnectionInterface $conn, $msg)
+	{
+		$conn->send("Never talk to me like that again!");
+	}
+
+	public function onClose(ConnectionInterface $conn)
+	{
+		$this->clients->detach($conn);
+		echo "Connection {$conn->resourceId} has disconnected\n";
+	}
+
+	public function onError(ConnectionInterface $conn, \Exception $e)
+	{
+		echo "An error has occurred: {$e->getMessage()}\n";
+
+		$conn->close();
+	}
+
+	public function sendToClients($message)
+	{
+		foreach ($this->clients as $client)
+		{
+			$client->send($message);
+		}
+	}
+}
\ No newline at end of file

--
Gitblit v1.8.0