1

I have a chat feature in my app using JSQMessagesViewController (https://github.com/jessesquires/JSQMessagesViewController).

It makes an API call to my server every 5 seconds to get all the chat messages between two users to populate the chat view with those messages. It was suggested I turn that into a socket connection because making an API call every 5 seconds will be hard on the battery and a waste of API calls.

How do I turn my chat feature into a socket connection with my server?

Are there any libraries in Objective-C that will help me accomplish this? And also, I'm pretty sure that I'll have to set this up on the back end too, so are there any resources as to how to set this up on a PHP Laravel backend?

1 Answer 1

0

You should be able to accomplish this using a couple mature libraries on both the iOS frontend and the PHP backend.

iOS: SocketRocket

https://github.com/square/SocketRocket

PHP:: Ratchet

http://socketo.me

They both support RFC 6455 so should integrate pretty easily.

Since you are using PHP, I'm going to take a stab and guess you are using Apache? If so, here is some more information on setting up websockets to work with Apache which can have issues with connection management: Setting up a websocket on Apache?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the info! I'll link my friend who's doing backend part so he can see if this is doable. We'll read up on this stuff a bit, and I'll accept this answer shortly after when we're confident that this can help us.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.