My objective is to implement a messenger in a client/server model. However, in the clients, one client will be a web browser and another would be an android phone. So i need to develop an android app as well for a client.
For web server I intend to use Lift with Scala.
I wish to use Comet for messages in a fashion similar to described here
http://simply.liftweb.net/index-2.1.html#Next
Although this technique might work fine in web browsers, I don't think it will work on the android app.
What solution do I have for this?
How do messengers like whatsapp work?
Quickness in sending and receiving responses is an important factor here which is why I chose the Comet model ( and also its ease of implementation ).
However, I'm open to new suggestions and ideas for incorporating this functionality. Please guide me through....I'm also open to other languages for the server that may be better suited to the task since I haven't started development.
Ignite Realtime has a xmpp library for android (and you can use openfire as server)
http://www.igniterealtime.org/projects/index.jsp
here about gtalk/hangouts https://developers.google.com/talk/
You can do something like https://github.com/nafg/reactive/blob/v0.4.0/reactive-web/src/main/scala/reactive/web/SsePage.scala -- an implementation of HTML5 server side events in Lift for reactive-web.
You'll probably want to use Lift's RestHelper support to develop an API that your android app will communicate with. RestHelper (or any code in your application) can send messages to your actor, and can respond by executing any code - not just a partialUpdate. In terms of sending to the actor, while I don't have any concrete examples for you, these links may help you get started:
Sending messages to a named comet actor with REST
Sending messages using Async REST
Asynchronous REST Support in Lift
Related
I'm trying to create a chat application and I need a little bit of guidance. I have a login system in place which is working. The user logs in/registers and everything is stored in a mysql database on the server.I know how to handle post requests and send stuff back.I have a recyclerView that can display the messages, but my problem is as follows:
Let's say I have 2 android devices: Android1 and Android2. Android1 sends a message to Android2. The message gets stored to the server. How do I tell the server to direct that message to Android2, and how do I make Android2 receive the message.
What if Android2 was offline at that time.Do I create some sort of response from the phone to tell the server that the message wasn t delivered so it can be sent again? And now how do I program the server to send the message again?
The messages table should be something like- senderId, receiverId, message; or what's the best way of designing it?
I found out about that I can do it either by using GCM, PHP and MYSQL from here http://www.androidhive.info/2016/02/android-push-notifications-using-gcm-php-mysql-realtime-chat-app-part-1/ and also that I can use XMPP. Which approach is best? I prefer the first one because I understand it and it's easy to implement. I have no idea what's happening with XMPP. I created a windows server using firebase, but can I still use my php one somehow ? And also the connection confuses me. I have facebook login implemented. Are there any good tutorials on the xmpp+android out there. I found some, but they are unclear.
Edit: Why is this question getting down votes? What's so wrong with it?
I had to face exactly the same situation as this sometime ago. What I have found in my researches was:
Use Telegram API: telegram is a well consolidate open source app for chat messages, it handles all aspects of it, including security and all the UI stuff. Its license, although, oblies you to make your code open as well;
Use Google Cloud Message Service: GCM allows you to send push to many devices using either REST or XMPP. Even if you're using GCM you'll have to implement a lot by yourself. In my humble opinion this is the best solution;
Implement a socket to connect the clients with the app server: this will required a whole lot of work, from sync to managing the power that your app consume, I wouldn't recommend you to follow this;
Understand the basics...
Extensible Messaging and Presence Protocol (XMPP):
Is a communications protocol for message-oriented middleware based on
XML (Extensible Markup Language).1 It enables the near-real-time
exchange of structured yet extensible data between any two or more
network entities
REST:
Is an architectural style consisting of a coordinated set of
architectural constraints applied to components, connectors, and data
elements, within a distributed hypermedia system. REST ignores the
details of component implementation and protocol syntax in order to
focus on the roles of components, the constraints upon their
interaction with other components, and their interpretation of
significant data elements.4 Through the application of REST
architectural constraints certain architectural properties are
induced: Performance, Scalability, Simplicity, Modifiability,
Visibility, Portability, and Reliability.4
From above we can understand that REST and XMPP are nothing more than protocols that you might end up using in order to pass your data through the components of your architecture. XMPP is the most optimized protocol for instant message communication, however, it is a bit more complex to implement. Fortunatelly, GCM support both protocols.
A possible architecture...
An instant message app is like any other client-server App. What is crucial to them is the need to notify the clients of updates that happen in the server. To do so, you need a proper way to communicate two clients. Usually this is made through a common app server. If you decide to go with GCM approach (my suggestion), you would have the following components:
GCM App Server: Responsible to manage the token generation and forward the received message to their targets;
Custom App Server: back end of the system implemented by you;
Client: web, android or iOS device that will receive push notifications;
It all starts when client opens the app, it will then make a call directly to GCM to request a token. Once it possess a token, the device should synchronize it with Custom App Server - so it knows everybody connected to the system and how to get to them. Custom app server maintain the token information in DB. When a device wants to send a message to another one, it will send a request to the custom app server which will, by its turn, retrieve the token of the target and forward the request to GCM App Server. It will then make a push to the target.
A Real Example...
As I said, I had to do a simmilar solution as I described above. The result of my work can be found in the following repositories:
Instachat Android: contains the source code for an App that uses GCM - it looks a lot like Whats App;
Instachat Core: a back end implemented using Spring Boot;
Both apps above were tested for a single one-to-one conversation using GCM and REST protocols, however, I'm still working on that and many bugs are present but the code can be used as a reference in order to understand the proposed architecture.
Hope I could help.
You can use GCM for sending and receiving messages.
You just need to send your messages to the receiving device through GCM, it will take care of it even if the receiving device is offline.
I used socket service for chat. so, I recommend you to use socket for
that. As compare to other, it will get quick response and all that you
want.
I'm developing an android app where I would like to fetch some data (mostly text) from the internet but not necesseraly from a website! I would like to have a server that allows clients to fetch some text data. What kind of server fits my goals the best? Http or maybe simply tcp? I don't know much about http so I don't know if it matches my goals and/or if it handles well a kind of text "database".
Edit:
A use case could be: people could write comments and send them to the server. Then clients could refresh their app by fetching new comments from the server. Therefore I'M asking what kind of server could best handle services and kind offre database if needed.
I like using NodeJS in combination with ExpressJS for such purposes. This combination allows you to easily work with HTTP/HTTTPS which is allowed by practically every firewall or proxy server. As of the latter reason I recommend you to use HTTP instead of an own protocol. Furhtermore, Java offers the HTTPURLConnection client which is very easy to use. Moreover, securing traffic with TLS (SSL) is very simple. In addition, NodeJS is resource efficient, runs on Windows, Linux and even on OS X.
For getting the text you can use HTTP GET request handled by the get() method of the Express instance.
This compact tutorial helped me to get familiar with Express on NodeJS.
Without knowing what your use-case is it's difficult to make a good recommendation.
With that said you may find something like https://parse.com/ suitable.
They provide an Android sdk and the 'getting started' tutorials will have you up and running in no time at all.
I'm writing an android app that uses GPS. It sends the NMEA string in a JSON object back to a django app I've already written (for similar use with an arduino+GPS). In order to send the data, I'm using sockets (the socket connection is on a intentservice, the gps code on a regular service).
The sockets are handled by the python tornado webserver, which receives the json object and adds the data to a PostGIS database with the appropriate django model, while still letting me browse the app from a browser like you would normally.
These are both my first android and django apps and I'm looking to improve them as well as my own coding/knolwedge of both platforms.
I'm just wondering if there are better, smarter ways of accomplishing these tasks.
Have a look at this third party rest framework (DRF): http://www.django-rest-framework.org
Gives you a django side solution out of the box. There are others (tasty-py) but in my opinion DRF is the best there is.
No need to do anything with sockets i suppose...
I'm creating a native mobile project that will use SocketIO on NodeJS as the communications API.
We would like to use the callback functionality of SocketIO, but on native iOS (or Android).
However, the callback functionality doesn't appear in any client implementation of WebSockets that I've found so I am guessing it is a feature exclusive to SocketIO?
If so, what is the header information before the payload that socketIO uses to make this possible.
Over the wire I can see some binary before the JSON payload, but I'm not enough of a JS guru to analyse how the callback functionality on the client side is done, so that I can replicate that in ObjC and Java.
Socket.IO is not just WebSockets, but many protocols and work arounds that it will use and fallback to older ones with attempt to establish most reliable and real-time communication layer.
It is actually bunch of protocols. So if you are looking to communicate with Android or iOS, then consider one single protocol, that would be pure WebSockets like this one: https://github.com/einaros/ws
Then you need to have native WebSockets library for Android and iOS. Although do not expect they to behave the way you get use to in node.js as those platforms are totally different. There might be pull of messages instead of event-driven (callbacks).
WebSocket it self is message based protocol and sends data over TCP as full or partial messages with extra framing (header) for each message that contains some data about message, like type, length, masking etc. You don't need to get into low level understanding of WebSockets in order to use them.
Socket.IO sends JSON data in their messages and just does own job to make sure there is neat and usefull way to emit and catch events.
Please check few libraries like: https://github.com/pkyeck/socket.IO-objc for iOS (socket.io client), or https://github.com/koush/android-websockets
Those libraries actually handle their callbacks so you don't need to understand how WebSockets or Socket.IO works inside.
My edit of Maksims wasn't accepted yet so I just wanted to provide a concise answer for anyone else looking.
SocketIO
Does have a header that packages each message, so it requires the use of a native SocketIO implementation, not just a WebSocket implementation.
https://github.com/pkyeck/socket.IO-objc
Is a library native to iOS that does implement SocketIO and it also implements the extremely handy callbacks feature available to SocketIO.
- (void) sendJSON:(NSDictionary *)data withAcknowledge:(SocketIOCallback)function;
I haven't found an implementation of the same for Android yet, and if it doesn't exist by December, will probaly create one myself.
This is not really a problem, more like a general X vs. Y question.
So I'm experimenting with c2dm on android using a server written in google app engine. At the moment I'm using the "App Engine Connected Android Project" as a template with some added code myself. So the generated code use RequestFactory for a bunch of stuff, like registering/unregistering devices, sending messages, etc.
My previous experiences with backend communication has existed of setting up a connection to a servlet, writing to it (json) and reading the response (json).
So here's the question:
What are the benefits (if any) with using the RequestFactory for communication with the app engine instead of just writing/reading from an URLConnection's input/outputstreams?
Or is it really just a matter of taste?
One disadvantage of request factory is that it is very slow in retrieving objects.. A custom servlet and http request are MUCH faster(10x-20x faster!).
Check out this post for more details RequestFactory slow on Android
I haven't used it myself yet, but the main benefit, as I understand it, is that it makes it really easy to authenticate against the App Engine app with your Android credentials. Doing that by hand is a bit of a pain.