I am developing a Cocoa application which involves a chat element. One approach I've considered is using Websockets to handle client-server communication. This would be particularly desirable because chats will also be displayed on a website, and using Websockets could make the implementation very simple.
So: would it be possible to use a WebView element, and use Websockets within it? (I know Safari doesn't support Websockets yet, so I imagine this is not possible?)
Failing that, are there any Websocket client libraries for C, Objective C, or any other language I could successfully embed within my application?
Suggestions welcomed.
To open a websocket connection, we need to create new WebSocket using the special protocol ws in the url: let socket = new WebSocket("ws://javascript.info"); There's also encrypted wss:// protocol. It's like HTTPS for websockets.
REST requires a stateless protocol according to the statelessness constraint, websockets is a stateful protocol, so it is not possible.
WebTransport is a new specification offering an alternative to WebSockets. For applications that need low-latency, event-driven communication between endpoints, WebSockets has been the go-to choice, but WebTransport may change that.
WebSockets keeps a single, persistent connection open while eliminating latency problems that arise with HTTP request/response-based methods. WebSockets generally do not use XMLHttpRequest, and as such, headers are not sent every-time we need to get more information from the server.
The only objective-c WebSocket library that supports the latest standard, RFC 6455 (at the time of writing this post) is SocketRocket (disclaimer: I'm author of it).
Both Unitt's and Zimt's client implementations are using deprecated protocols and don't seem to be maintained.
Here is an implementation of websockets for objective-c
http://github.com/esad/zimt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With