ZMQ Pusher and send message to just one user

89 views
Skip to first unread message

Fedot Serghei

unread,
Apr 27, 2015, 9:21:00 AM4/27/15
to ratch...@googlegroups.com
Hello,
I use for two months ratchet websocket...with session provider and everything (I already have 10 topics). In this moment I use it just for notifications and some javascript live changes! and to count online users by session and cookie etc....

But now I wan't to develop a private chat like user to user.I checked again the documentation and I don't know how to combine this two functionalities.

I.
 $numRecv = count($this->clients) - 1;
        echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n"
            , $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');

        foreach ($this->clients as $client) {
            if ($from !== $client) {
                // The sender is not the receiver, send to each client connected
                $client->send($msg);
            }
        }
II.
 $entryData = json_decode($entry, true);

        // If the lookup topic object isn't set there is no one to publish to
        if (!array_key_exists($entryData['category'], $this->subscribedTopics)) {
            return;
        }

        $topic = $this->subscribedTopics[$entryData['category']];

        // re-send the data to all the clients subscribed to that category
        $topic->broadcast($entryData);
How do I combine I with II ? (when i use conn.send i get disconnected from the server with "undefined" message and need to refresh )
I was thinking to make foreach user a topic! and send the messages to that topic ! But if one user its a little smarter he will send in console 

conn.subscribe('User2', function(topic, data) {
                console.log(data);
});



cboden

unread,
May 16, 2015, 12:23:57 AM5/16/15
to ratch...@googlegroups.com, fedo...@gmail.com
There various ways you could accomplish this. Myself, I would first try creating a unique channel for two people to communicate in privately. You can use something like uniqid() for the topic name and have users join that topic to have their private room. I'd need a bit more context on how you'd want this to work to provide more info (do they know each other by WAMP less ID, cookie ID, session ID, is it random, etc)?
Reply all
Reply to author
Forward
0 new messages