I'm trying to implement an iPhone Client which is communicating with a Java Server via TCP and/or UDP.
It seems that there are a couple of options how to do that and i'm a little bit confused right now. I'm also new to this Objective-C stuff but trying to get used to it.
I read that UNIX Sockets are available. I have to write C-Code for that right? Can i just write the C-Code into my ObjC implementation or how should i do that? Isn't that ugly? Or can i somehow write a C coded file and implement the stuff into an ObjC class?
Additionally i found out that i may use CFNetwork. But i can't find a good resource which tells me how to do that. Do i have to create a CFSocket first and then create the read/write streams for that?
After that i saw NSStreams should be also an option.
I'm a bit confused and don't know which technology to choose and how to implement the whole thing. I "just" need to add network functionality to an existing iPhone Application to transmit data. The best thing would be a class that i can instanciate (giving it a host, port, calling a connect function ...) and use it to send data.
What would you recommend? Do you have any hints or examples for me? That would be very great.
To make things easier, better to use combinations of NSStream and CFSocket and its related family.
Check "CocoaEcho" sample code in Apple's developer website.
I've been there with BSD socket, and it's a pain to do asynchronous behavior.
For UDP, you might just have to modify the socket type somewhere, or you could create an Objective-C wrapper out of BSD socket, and integrate with the existing TCP solution.
Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.