Iam using Ratchet Websocket Library for chatting on mobile application.
I have used following code: To Send / Recive Message:
class Chat implements MessageComponentInterface {
protected $clients;
public function __construct()
{
$this->clients = new \SplObjectStorage;
}
public function onOpen(ConnectionInterface $conn)
{
$this->clients->attach($conn);
echo "New connection! ({$conn->resourceId})\n";
}
public function onMessage(ConnectionInterface $from, $msg)
{
foreach ($this->clients as $client) {
if ($from !== $client) {
$client->send($msg);
}
}
}
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();
}
}
On iOS when user enters the chat screen I call Connection Open to open a connection between mobile and web. But When I disconnect Wifi. On server OnClose didn't get called. So Server didn't get notified that the current connection is disconnected. And when server send any message to application it doesn't get received by the iOS app. I want to know is there any way to detect in OnMessage function that $client->send($msg) is actually sent or not?