Listen to incoming HTTP messages on iPhone - iphone

I have to do a simple iPhone project as part of an university exam which consists in creating a simple instant messenger based on a client/server system using the Java Servlet technology (required).
What I would like to know is if there is a framework or some simple classes that make me able to listen for incoming http message from a server without make a request so that an iPhone can send directly to another iPhone an instant message.
Thanks in advance and have a nice day!
L.

From what I understand from your question, you need a listener. There are several 3rd party implementations that provide what you need. Basically you just need to open a socket for listening on a HTTP server running on your iPhone.
Try these, it should provide you with what yo need
CocoaHTTPServer.
MongooseDaemon

If youre looking for a way to receive message from WEB server - you may use Apple Notification service (here`s a good tutorial)
Another way is to use long-poll connection, but is not an easy thing to implement in IOS.
Maybe you can check for incoming message by requesting web server from iPhone (ex. every 10 seconds)?

Related

Socket connection between rails and iphone native app

I have an iphone app with rails serving as a backend server.
Now I need to implement a chat functionality using sockets connections.
A lot of examples show you how to implement chat using sockets in browser.
What I need here is how I can implement an application where you create socket server in the rails app , and the client in iphone app which listens to the channel I give them.
I tried using faye(examples given only how to implement client in the browser) and using fayeObjC library for iphone to create client, but am not able to listen to the channel from this library.I know I must be implementing it wrong here.
I'll share my code also here, but first I need to know is there a better solution than this?
Also I appreciate some links to some examples where socket server is in rails and clients are iphone app.
Appreciate any help and mostly need a right direction to implement it.
Update
I tried the faye combination again and it worked.Although still looking for more solutions.
You can check about TCP sockets:
http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server
Chat Application Using Ruby
http://quickblox.com/modules/chat/
http://caydenliew.com/2011/11/ios-mac-os-communication-with-asyncsocket/
http://www.macresearch.org/cocoa-scientists-part-xxix-message
Next link is a comprehensive Networking Guide - Using Internet Sockets
You must keep in mind two major problems to peer-to-peer communications (Chat): reachability and how to receive new messages while your application is in the background (get notifications).
For the last you can use APNS approach: an invisible notification will be pushed to the iPhone indicating that a new message is ready to be read. So your app will make a request for unread messages (what app like WhatsApp does).
Besides TCP sockets you could use websockets (HTTP - so there are no firewall problems).
Best in class - Socket.IO.
Here you will find the wiki https://github.com/learnboost/socket.io/wiki (you will find there an extension for Ruby also)
Here an example for iOS chat client for socket.io & node.js backend
Jabber
Another option: XMPP - "stands for eXtensible Messaging and Presence Protocol. Such a protocol is open-standard and oriented to message exchange (builds and maintains by Jabber community). Message exchange happens near real time, so it is an ideal infrastructure to build chat-like applications. The protocol also implements a mechanism to notify presence information (whether a user is online or not) and the maintenance of a contact list. XMPP is a thorough protocol, which has been adopted also by big companies like Google to build their Instant Messaging service."
Here you will find all about developing a Jabber Client for iOS (enable users to sign in, add buddies, and send messages; how to install and configure a jabber server, create accounts, and interact with the server from an iOS application http://mobile.tutsplus.com/tutorials/iphone/building-a-jabber-client-for-ios-server-setup/
I know that SocketRocket by square is a strong native Objective-C library. But it doesn't offer the channel abstraction you seem to be looking for.
If you would consider outsourcing the WebSocket connections then you could use a hosted service like Pusher, who I work for. You can publish messages (trigger events) on channels using the pusher-gem. And you can subscribe to channels and receive messages using one of Pusher's Objective-C libraries.
Other solutions will also have Objective-C libraries and you can find a list of them via this realtime web tech guide.

How to create iphone app to call via wifi/3g (VoIP)?

I want to developed an iphone app, allow to call via wifi/3g.
Please provide me example statement to:
How to Client send request to sip provider?
How to Sip provider establish a connection to other Client?
thanks,
You should definitely take a look at this project: pjsip that will give you a strong starting point for your application.

How can I build/install/run a server program to communicate with the iPhone?

I'd like to play with the idea of creating a server program that communicates with an iPhone app over socket connections. I've found several guides within Apple's documentation for client side programming (with CFNetwork, NSStream, etc) but I don't know where to begin on programming the server application, or even what language to use, or for that matter, how to deploy and run a server application on my current web hosting package through Go Daddy. A simple instant messenger style application example should get me started, but any advice is appreciated.
if you want to create socket connection is better to use CFNetwork , it has more flexibility for you I already used NSURLConnection but CFNetwork has better performance. this is my steps and how I developed my app :
configuration of server
selection C++ for my server side (service)
start to develop a client-side app for iphone to connect to server using NS classes
but I had some problems in sending and receiving message to and form server . so I changed it to CF classes it works better and faster now.
The easiest way to handle server-to-device communications is to use APNS (Apple Push Notification Services).
Communication in the other direction (device-to-server) can be handled simply with NSUrlConnection.
If you want to write your own socket code for this, well - good luck with that.
Do you want your client application to be able to run on more than one OS? If so, you might want to stay clear of anything Apple specific. Although, if you strictly want to run on iOS, using MusiGenesis' suggestion could save you a ton of time.
I have found that Python and Perl are both pretty great for socket programming. I know that Python has several libraries built in for handling HTTP requests etc. If you want to run your server as a daemon, I found this code very helpful:
http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
Here is a general python sockets guide:
http://docs.python.org/howto/sockets.html
Good luck.

How does iphone apps interact with server?

I am a new programmer who is new to iPhone development and server stuff. I have a lot of questions to ask.
You don't have to answer all the questions; any help is appreciated!
How does iPhone apps interact with server?
Is there a particular kind of server i should use to interact iphone app with server?
If there is no particular kind of server then what kind of server can be used?
What are their advantages and disadvantages?
What should the iPhone app (which is the client) do in order to interact with the server?
How does the server know which iPhone to send data to?
What should the server do in order to interact with iPhone app (client)?
Your best bet is to have your iPhone make web requests of a web server. Your iPhone app acts just like a web browser, making http requests to a web server, and parsing the response.
I'm building an app right now that hits PHP scripts I've written that do database work, etc, and return JSON objects. It's not fancy--I could have built a whole SOAP or RPC web service, but I didn't do that, it just makes GET requests with query-string arguments.
There are handy libraries you want to know about. Google "iPhone JSON" to find the JSON library written by Stig Brautaset, that's the one most people seem to be using. Also, rather than putting yourself through all the hoops that the iPhone's built-in web client framework requires, go get ASIHTTPRequest, a very powerful and MUCH simplified web client library.
As a general rule, you want to do as much processing on the server as possible. For instance, there's a place in my app I'm searching for events happening within a user-specified range of their local coordinates ("within 10 miles of me"). I wrote PHP to build a latitude/longitude bounding box, and query from the database based on that. That's WAY faster than bringing a bunch of events down and then asking Core Location to calculate their distance from where I'm standing.
You've asked quite a few questions so I'll try my best to answer them all:
First, you need to be a bit clearer, what type of server are you talking about? Email server, web server, lolcat server, it depends.
At the basic level, the iphone communicates over the internet. The internet uses Internet Protocol, and there are two standard protocols built atop of IP: Transmission Control Protocol, and User Datagram Protocol. Each has it's own uses and functions.
TCP/IP and UDP/IP make up the backbone of internet communication.
A more specific application protocol is built atop of these two internet protocols, with a specific format to a given application. For example, HTTP is the standard protocol for transferring HTML and other Web information between a web server to a web browser client, over TCP.
So, your iPhone would use whatever protocol is required to commuincate with the server. For more common server communication, the iOS SDK provides methods to construct messages (for example if you wish to make an HTTP request to a web server, you can use initWithContentsOfURL to send a GET request).
If you built a custom server, then you will need construct the required message protocol on the iphone, and send it to the server, using either TCP or UDP (whatever your custom server expects).

write own mail client to send Mail using SMTP/POP3 server on iphone

I am trying to develop application to send mail using configured SMTP client rather than iPhone's default MailController.
How can i implement this functionality? Is it possible to design such client?
Thanks,
Jim.
It is possible, however, unless you want to develop your own implementation of the protocols and start opening TCP ports, etc, you might want to look into OSS tools that provide these features.
this might help you out.