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?

Community
  • 1
  • 1
Rafi
  • 1,902
  • 3
  • 24
  • 46

1 Answers1

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?

Community
  • 1
  • 1
Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
  • 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. – Rafi Nov 20 '15 at 00:35