WebSockets In Swift — IOS Development
What is WebSocket ? Why do we use it ? And why did I used an image of clock?
Well WebSocket is a communication protocol that follows stateful protocol and helps us to build Real Time Application (RTA) & thats why I used a clock image. A simple example for it is chat application. If you want to learn more about WebSocket please refer to my article where I’ve made a comparison between REST & WebSocket.
For this tutorial I am going to use a demo api you can get it from here. Enough of the theory lets move to practical implementation.
Practical Implementation For WebSocket In Swift :
In the code above we have created a UIButton and added it to the View & added the button target this button will help us to disconnect our WebSocket session. So on touchUpInside action our button will call the function closeSession() on line 34.