Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to incorporate WebSockets into a Cocoa application [closed]

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.

like image 341
netflux Avatar asked Apr 18 '10 21:04

netflux


People also ask

How do I add a WebSocket?

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.

Do WebSockets adhere to rest?

REST requires a stateless protocol according to the statelessness constraint, websockets is a stateful protocol, so it is not possible.

What will replace WebSockets?

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.

Does WebSocket keep connection open?

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.


2 Answers

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.

like image 80
mikelikespie Avatar answered Sep 30 '22 23:09

mikelikespie


Here is an implementation of websockets for objective-c

http://github.com/esad/zimt

like image 24
diclophis Avatar answered Oct 01 '22 00:10

diclophis