I want to implement a text chat functionality with the help of "Socket Programming" in iOS. I know about the process to connect to a server with the help of host and port like:
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)(@"127.1.0.0"), 80, &readStream, &writeStream);
But I want to know how I can make socket connection between two chat users during chat?
Do I have to use a server between chat users?
You have two options. The one is using a server that two clients connect to. If you don't want that, you will have to implement TCP servers into the clients.
So aou defenitively need any kind of server, the clients can connect to. It's not pretty complicated to implement a server using CFNetwork. Just google for 'iOS TCP Server' or similar.
I'm not at the office today, so I unfortunately can't post code where you can start with, I'm sorry.
When I started TCP programming I found this tutorial pretty useful. Ray Wenderlich makes good tutorials though.
If you don't get it working, I will post some code on monday when I'm back at my code base :)
http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server