The community forums are in BETA and closed to the public.

Android Chat and Group Chat with PubNub

I have successfully built out a a chat and group chat application in Android, with backend Apache and MySQL, employing websockets to send and receive messages. I wish for a more dependable method of sending and receiving messages to the server and found PubNub. However, the use of channels is quite confusing in my app.

In summary, I simply wish to replace my implementation of websockets with PubNub and keep the MySQL database backend due to other features the app requires.

What is the best source or walkthrough to allow for this direct switch?

Channels are just a means of sending a message from a publisher to a subscriber (or many subscribers). You create channels for whatever you need: chat rooms (private or group), broadcasting (1 to many) or whatever the purpose.

If a client (some device - browser, smart phone, embedded device, a server process, whatever) is subscribed to a channel called "system_notices", then anytime a publisher publishes a message to that channel, all those subscribers will receive that message in realtime.

There is no need to make some direct connection from publish to subscriber as it is completely decoupled. Subscribers subscribe to channels and publishers publish to channels. And any client can be both publisher and subscriber of just one or the other.

This getting started tutorial might help explain:

I understand the concept of channels, but do not see a straight forward approach for implementation. Instead of using channels and the like, is there a way to simply use a feature subset of PubNub that would ensure a message is sent to the server and then as the user listens on that port for their messages, it again uses the pubnub subset to receive them.

There is an app that may have this functionality: I viewed the implementation of PubNub into a chat application chat application called Thumb Chat:

How have they implemented?

No, that is the function of channels. Listening on ports is hardwiring where has channel subscriptions is decoupled. Under the covers PubNub is handling the connections for you.

And this is how formal message queues (RabbitMQ and the likes) work, as well (there are some differences though). But I assure you, channels are what you want and need and it is what Thumb Chat uses (it's how PubNub works, period - there's really no way around channels).

ThumbChat uses the PubNub Data Stream feature for all messaging in their app, including realtime messaging and sending emojis. Data Stream enables both unicast (1v1 messaging) and broadcast (group messaging) functionality. This allows the ThumbChat app to send messages between users in under a ¼ second...

Above is from the Thumb Chat blog (as you might recognize). Data Stream can be interchanged with channel. Simply put, messages are sent and received on channels.

In the Thumb Chat screenshot, the channels are Hockey buds, wifey, Steve and Aaron Hernandez. And actually, those channels (aka, chat rooms) could be called something different under the covers like hockey_buds or even RTGH-1234-HGWQ-8723 or whatever channel naming convention you wish to use.

I hope this is helpful. If not, just ask more questions and we'll keep drilling down.

So if I need to just enhance the websocket configuration that I have created, I can simply use one channel that all users can subscribe and post to. Then the user would listen to the channel and as a message that matches their user id comes up, then they accept it?

Would that be the best way to incorporate? I do not see a reason to switch channels once connected as I still want all the messages sent into my database

Comments to this discussion are now closed!