Communication between android app and web server. Is nodejs a good option? - php

I went through several topics on SO but I am not sure what fits my needs as I am newbie.
I am creating an Android application for my website.
I reckon that the users can be over 800000 online at the same time.
Users will be able to:
- Submit data through the application
- Read news and updates
I want the updates to happen in real time..
The question is what approach or technique should I use?
In some SO topics is mentioned that there should be on the server side some php files that will accept http/post/get requests and they will return JSON data as feedback.
Is the above-mentioned a proper technique to serve a huge amount of users at the same time(for my standards "huge" means around 800000 users at the same time)?
I recently came across node.js. From what I read it seems like it can act as service where a user/ app can request or post data.
Can anyone give me a suggestion or links where the things are clear? How can I make sure what approach is the right one for my application?
Whatever the case is can anyone describe the right way of doing this thing?
For example: How Android chat aplications suchs as whatsapp, facebook etc work? How they do it?
I do NOT want you to post any code.. just ideas!
Thanks in advance!

If you want create an app like Facebook, Snapchat ... YES you must have a WebService, an API.
The API is linked with your database like your website and return to the app JSON, with the content of your app.
Your API (web service) can be programmed in various language as PHP, Node.JS ...
If you want to know Facebook had their API in PHP before that they created their own language.
Some other app have their API in other language.
I don't really know what is THE BEST language, the BEST language is the language which you are good with, and know it.

I think think nodejs will be best option.
NodeJs is helpfull when there are large number of clients.
Nodejs works best when building chat and gaming applications.
I think this link will help you a lot to learn nodejs.
If you are asking how facebook and whatsapp works they are implementing websockets which provides bidirectional flow of data helps in real-time communications between clients.

If your scenario is sending chats back and forth nodejs is a really good option, Most of the online tutorials you will find about nodejs develop a chat application and its super easy to do so with nodejs. Infact the biggest catch with nodejs is its easy configurations and deployment plus its lightweight. However it might be a good idea to have a look at XMPP as tech giants such as whatsapp use it to send messages and maintain presence. This link can be a good head start for nodejs learning http://code.tutsplus.com/tutorials/nodejs-for-beginners--net-26314

Related

implementing a chat webapplication

I need to develop a web application with a chat feature, and I would like to know if there are any sophisticated ways to create a realtime web-application with a push engine.
I know jQuery, and I can handle to create a chat web-application which, in the client side, check every period for new messages, and show them, but I don't like this solution and I was wondering if there are any better ways to do it.
In my research I discovered the existence Ajax Push Engine project, and it looks like what I need, but when I was navigating in their website I found it not very well done and somehow incomplete, so I was wondring if there API is stable enough to be put in a production environment if not are there any other solutions?
Sorry if I made it long, any help/hint/link/suggestion would be very welcomed :)
EDIT
I would like to specify that I'm working with PHP in the server side
Here is an implementation in NodeJs.
http://dhotson.tumblr.com/post/271733389/a-simple-chat-server-in-node-js
I recently (year 2012) developed an application in ASP.NET MVC3 where I used SignalR for real-time messaging between server and client. At their own site, they describe SignalR like this:
ASP.NET SignalR is a new library for ASP.NET developers that makes it incredibly simple to add real-time web functionality to your applications. What is "real-time web" functionality? It's the ability to have your server-side code push content to the connected clients as it happens, in real-time.
... and they give the following example of what you can use SignalR for:
SignalR can be used to add any sort of "real-time" web functionality to your ASP.NET application. While chat is often used as an example, you can do a whole lot more. Any time a user refreshes a web page to see new data, or the page implements Ajax long polling to retrieve new data, is candidate for using SignalR.
Further, based on my experience, I believe it is very simple to set up, easy to use, and have a good github page with well-written documentation that gets you going in no time. I can highly recommend it :)

What is the best way to connect an android application and a php server using sockets?

What is the best way to connect an android application and a php server using sockets? I am trying to implement a chat system between multiple clients, but I know that PHP does not allow multithreads.
Sorry for not giving enough information about what I intend to do. I basically want to create an app simmilar to google latitude, and I also want to implement a chat system between the users. I have aldready decided that I am going to use a MySQl DB and therfore a PHP server so the client communicates with the DB using JSON for data exchange. I am quite new to this and I don't know how the architecture Client-Server-Client communication should look like. I found out that the easiest way to do this is using HTTP requests, but I don't know how I should implement this.
I think you can use jabber protocol, install any xmpp server and you can connect to that from android, this is standard for chat applications
use xml-rpc base php webservices for chat server. your chat client will contact to chat server throught web services.
*I was going to make this a comment but I ran out of space, plus it does have some answer-y qualities to it.
This question does not contain nearly enough information for anyone to usefully help you. How do you think it should be done? You can't ask people to critique an idea when you haven't told them what your idea is.
PHP is the wrong language for this, because (as you rightly point out) it can't be multi-threaded - amongst a multitude of other reasons. I personally would recommend Node.js (or possibly Java), but that's just my preference.
If you still insist on using PHP, take a look at this. It might give you a point in the right direction for a non-blocking multi-IO setup such as this - but you're letting yourself into a whole world of unnecessary complication by doing this in PHP.

Android and http communications

I have looked on here and anddev for a suitable response, but haven't found anything suitable.
Here is the question: My friend has an instant chat application with iPhone, and since I have some basic android experience he asked me to check out "porting" it to Android. So before I set up the UI, I decided to look into php which I don't have much experience with. I know the UI will need an array to call contacts, but I'm not sure about retrieving the information from the php.
How do I know if I can use his script or not? I haven't found any good tutorials about Android and Php - has anyone found one?
I might as well learn this stuff now because my next app will require an online database to be used in it - I know his has users and passwords, and he'd like to be able to send im's between iPhone and Android clients.
Thanks for any help you may provide!
EDIT:
Yes, this issue is more related to http requests from android to a remote server; I have changed the tags and subject accordingly, but would still appreciate a guide to android-friendly php writing. Thank you!
There really isn't Android-Friendly PHP but there is mobile friendly PHP. Basically, you need your PHP scripts to emit something that is easy to parse in an application (like XML or JSON) rather than the standard HTML. After that, all you need to do is figure out what the API should look like on the server side. That is, what functions does the server need to provide and how is it going to provide them. Are you going to use simple HTTP authentication or are you going to use something more complicated?
With regards to his chat application, I would imagine that if he already has an iPhone version, then you won't need to mess with the sever side at all. All you need to do is figure out what URLs and parameters to use for what operations. You also need to ask him what data format his server uses. If it's XML, you need to find an XML parser, if it's JSON then you need to find a JSON parser etc. (there are plenty of tutorials on how to do both in Android via Google). I would start by asking him, at a high-level, not with Objective-C specifics, how his chat application communicates with the sever. You can then use that to build your application to communicate in the same manner.

How should I make my PHP API work for an iPhone app

The title may not be the best way to describe my question.
I am working on another social network type site similar to a facebook site in PHP. I would like to eventually pay someone to build me an iPhone/iOS app that will be similar to the facebook iPhone app but work with my PHP site instead.
So a major concern for me will be to have the iOS app to be as fast as possible for the users.
From others experience, what would be the best way for my PHP sites API to get the data for the iOS app? I would think that a simple REST type API that returns results with JSON and XML formats would be the way most sites work with an iPhone/iOS app?
Is my theory correct or is there a different way to do it? Please help
Yes, that's the best solution. The only alternative I know of would be to connect with via TCP/IP, and skip the higher level HTTP protocol. That means using sockets.

What are my options for creating an iPhone app from an existing PHP website?

I have an existing PHP/MySQL website that relies hugely on form POSTs for things like signing up, logging in, searching etc. I now need to create a native iPhone app for it. The business requires a native app for marketing reasons, I can't get away with a mobile optimized website.
I'm looking for suggestions from someone who has already done this - how did you rewire your website to POST/GET data from the iPhone app? I'm guessing I'll have to send/receive data as XML, which is then parsed by the server and client. Is there anything simpler or any framework that can make this easier?
Thanks!
If you don't have some sort of webservices or API to connect through for the website I would make that my first priority. While you can scrape HTML and send POST requests, it can get quite messy FAST. I've created iPhone apps which talk with webservices through SOAP requests, and have built an iPhone interface to a site, which wasn't pretty. It is very doable, but it is also very frustrating if anything changes on the webpage.
If you are looking for a decent library to help you get started with POSTing against forms check out the ASIHTTPRequest library at http://allseeing-i.com/ASIHTTPRequest/. If you look at the site there is a 'How to Use It' page with 'Sending Data with POST or PUT Requests'. Otherwise you could just use NSURLRequest and NSURLConnection and handle everything yourself.
It depends a lot on what you are presenting. You may be able to put a lot of your php heavy interfaces into web pages. The web pages and all related resources would be local to, and formatted for the iPhone. You can look at PhoneGap for examples of how to host local web pages and communicate with the host application.
I have been writing an eBook reader. About half of the user interface is done through local html files. In my case there is no network access, but WebKit is the easiest way to style text.
As long as your application does not look like a web page, it is fine if it is a web page. That may simplify big chunks of server interaction, especially things like login that only happen once or rarely.
Jonathan,
I would recommend taking a look at the Apple provided SeismicXML sample app. It uses the NSXMLParser to parse XML in a asynchronous fashion which will be huge for your app. It also shows how to use a NSURLConnection to make the request off of the web. You can use the NSURLConnection (which is also asynchronous) for POST/GET requests.
As mentioned in another answer, the ASIHTTPRequest library from allseeing-i.com is an excellent library but all of the features you want can be done using the built in Apple APIs if needed for your business requirements.
Hope this helps!

Categories