Building a mobile app (Course Assist) Part 2: Setting up real-time data transfer functionality using SocketIO

building course assist

From the time Course Assist was just an idea in my head early last year I’ve known adding web sockets to the project will be an absolute headache. That was until a few weeks ago when I had a light bulb moment 💡and realised I could easily set it up without finishing every painkiller in my mother’s medicine cabinet😂. Let me break it down, the project features a sort of feed page kind of like your news feed on Facebook and also a notifications page. Now the thing about the Facebook news feed or Facebook notification page is it updates in real-time. You don’t need to restart the app for you to get new posts or notifications from your friends on Facebook, and that’s exactly what I want to implement in Course Assist. In other words when a person posts a question in the user app I want the feed in the expert app to automatically update without any manual page refreshing or when they get a new notification the notification page automatically updates.

Originally I used Django channels which according to the official documentation is a project that takes Django and extends its abilities beyond HTTP – to handle WebSockets, chat protocols, IoT protocols, and more. Now Django channels as it is was already very complicated to set up and deploy then to make matters worse because I was using Django rest framework I couldn’t use channels the way it was built to be used, 🤦🏾‍♂️I had to improvise.
How? You may ask. So essentially what I did was use the Django channels setup in my Django backend as a middleman notifying the User app to refresh the page in the Expert app every time a post or notification is sent. And this was the plan until I discovered deploying a Django rest backend with Django channels is a whole nother complicated setup on its own, one that I didn’t feel was necessary for such a simple use case, It’s not like I’m building a chat app or something. Then just when I thought I’ll have to brave this nightmare problem I had a light bulb moment. I realised I could use the same plan but instead of using the very complicated Django channels, I could use the very simple SocketIO which according to the official docs is a bidirectional and low-latency communication for every platform. I quickly read the documentation and watched a couple of youtube videos and I was ready to get started. The process is completely the same as before the only difference was that a Nodejs server was going to be the middleman. Interesting fact, you can set up a SocketIO server in any language, not just javascript. I built the server in less than 10 minutes and was ready to start sending real-time data between my apps.

Ran into a few errors here and there but in the end, setting up the feed and notifications with real-time data transfer was successful. I haven’t yet deployed the Nodejs server but I’m hoping that when I do, the process will be as smooth as it was setting it up, make sure you stay tuned to the blog to see how that goes in the coming parts.


Leave a Comment

Your email address will not be published. Required fields are marked *