You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classSocketPush
{
/** * Helper Function to broad a message. * The metadata required to send message should be part of message itself * Example usage: * SocketPush::SendBroadcast(SocketPush::constructMessage(PusherServer::$PUSHABLE_USER_PREFIX . '1' * , PusherServer::$ACTION_PUSH, "coming your way")); * @param $msg string */publicstaticfunctionSendBroadcast($msg)
{
$loop = Factory::create();
$connector = newConnector($loop);
$connector('ws://127.0.0.1:8080', [], ['Origin' => 'origin'])
->then(function (WebSocket$conn) use ($msg, $loop) {
$conn->remoteAddress = '127.0.0.1';
$conn->on('close', function ($code = null, $reason = null) {
});
$conn->send($msg);
$conn->close();
}, function (\Exception$e) use ($loop) {
echo$e->getMessage();
$loop->stop();
});
$loop->run();
}
}
I am using push notification using ratchet, and so , whenever I need the server to send a message to a client, I call the sendBroadcast method of this client.
What this does is, everytime a message needs to be sent, it initiates a connection , then sends the message, then closes it(this sounds like unnecessary overhead)
Is is possible to keep the connection open at all times (if for some reach it disconnects, reconnect), and , call the same send broadcast method from other classes to send message ?
The text was updated successfully, but these errors were encountered:
Your SocketPush class is run inside your website (not within your Ratchet) app, correct? If so what you're doing is correct. It's the same as the push tutorial just using a different transport. With each client request to your website you do have to open and new connection every time as the environment is destroyed at the end of the request.
I have made a helper class like :
I am using push notification using ratchet, and so , whenever I need the server to send a message to a client, I call the sendBroadcast method of this client.
What this does is, everytime a message needs to be sent, it initiates a connection , then sends the message, then closes it(this sounds like unnecessary overhead)
Is is possible to keep the connection open at all times (if for some reach it disconnects, reconnect), and , call the same send broadcast method from other classes to send message ?
The text was updated successfully, but these errors were encountered: