Web Sockets a super quick intro.

During the early stages of my time at the Flatiron School my group and I decided for our mod 2 project we were to build a messaging application that translates the text to the language a user chooses. While successfully creating the app we ran into one important feature that we struggled against. The messages were not sending in real time. Our TCF suggested to look up Web Sockets but warned us that it would be difficult. We took on that challenge but we ultimately could not do it.
Fast forward to mod 5 where we built our final projects, I wanted to have a chat feature for my application to have a more social feel to it. My app was a Spotify Jukebox where users can suggest what song to be played next. Remembering the difficulty we had all those weeks before in mod 2 I was adamant to make it work……and I did. It was amazing that in those short weeks something that took nearly a whole day to try and figure out I was able to make work in a matter of hours.
So what exactly is web sockets?
No it’s not where Peter Parker puts his web so he can swing from building to building. Web Sockets allow real-time interactive communication between the client browser and a server. It is different from HTTP cause it allows bidirectional data flow.
A quick summary of HTTP is that you need to request is needed in order to get a response. So in order to receive a new message in a basic chat app, you would have to constantly ask the server if there are new ones.
What makes Web Sockets different is that you do not need to send a request in order to get a response. Since data flows both ways you just have to make it listen for any new data.


What exactly can I use it for?
Like I mentioned previously a good time to implement web socket is for applications like chat apps. Any application that needs real time feedback such as multiplayer games can benefit from Web Sockets.
How can I start using Web Sockets?
While researching how to implement web socket for my final project i stumbled upon another great blog that guides you step by step on how to use it. You can find it here. It worked out well for me because I was using React and Rails for the project. Did a couple of tweaks to the code here and there so that it worked seamlessly with my project and I could have not been happier when I first tested it out and it worked.
Conclusion
I know this was a very short introduction on what web sockets are. There are many other methods to implement it. I found the way that works best for what I needed to accomplish. This blog only scratched the surface but I hope it shed some light on this topic. I highly suggest to research on your own and continue to learn everything that you can possibly learn to further yourself as a developer.