Creating local server on an Android device - java

I have an idea for an application where one device is a server, and other devices connect to this server.
The clients would send data and call HTTP requests (or whatever is equal to them in this case), and the server would receive the request and act on it.
I understand there is such a thing as Sockets, but does this fulfill my requirement? Will I be able to call requests on the other device?
Example usage: The client clicks the + button, and the server increments the value.

Have a look at P2P, it uses Wifi Direct, so one device can be setup as a host server and the other devices can register to that as clients.
Check out the official documentation.

Related

can we send request to server which forward that request to some other IP address

I am making an android application which can control the user's PC or laptop remotely. Is this possible that I send any request from the android application to the server and then server forward that request to the corresponding IP/Port address of user's. A software would also be running on user's system which will receive that request and then respond according to the request.
I just know very little about networks so don't know whether is this possible or not and if possible then how ?
Any help would be appreciated.
You would need to either:
Use some PubSub service (like Amazon SNS).
Write your own service, where clients would register for notifications and you would send those notifications to the server where clients are registered and this server would notify them.

P2P communication , chat App (android)

i am using this tutorial as guide. i am creating an android app which is basically chat application. this uses socket programming to communicate .
i want to connect directly to device and deliver the message. the message does not go to server. server only tell me the address of the device thats it.
i followed the tutorial i mentioned above and this only works for the case where client and server are within same wifi/network. i want to connect to server from client irrespective of their network connection place. how do i do it from any network to any network.
i think i need to use port forwarding , but this is not practical . so we better use a server for keeping track of all the ip changes. and deliver the messages directly from the source to client. so how do i do it. please suggest any resources.
update
as of now what i studied is i have to use innetaddress to communicate if i am inside an wifi router.
thank you

GCM device to device messaging - how is it done?

I'm interested in how apps like WhatsApp implement this feature.
I've just read that it's bad practice to send the message directly from device to device, because someone can eventually get to the API key and send messages as my application.
What's the solution then? Having a server and making the devices only communicate with this server, so when I want to send a message to another device, it goes to the server and from server to that target device?
Also another question:
public void onMessageReceived(String from, Bundle data)
This is a method of the GcmListenerService. When is "from" different than the default senderID? Because I tried sending the message directly from one device to another and the "from" was still the default senderID that I got when I registered the app on the website.
Basically, you need a server to listen to upstream messages and broadcast then again to intended recipients.
You can find an article describing this here: http://javapapers.com/android/android-chat-with-google-gcm-xmpp/
The approach is pretty limited and not as flexible as having your own messaging server, but should be enough for a proof of concept.

A connection between 2 applications

I would like to manage a connection between 2 applications, they will run on diffrent phones.
The purpose doesn't really matters let's say that it would be some kind of a chat.
How can I create this connection between the applications? I know how to do it on pc java programs using the socket and the serverSocket classes but I guess it's diffrent in here since the phone might change his ip when he moves between networks.
So how would you do that? how would you create a connection between 2 applications/phones
Given the scenario you described in your comment, using Push Notification i.e Google Cloud Messaging (GCM) might be sufficient.
So, when program B wants update from program A, it will ask the server to push a notification (via GCM) to program A. Note that program A will not connect to the server every x time to check for updates.
Another out-of-the-box solution is to use SMS if the communication is not so frequent and messages are short. Here I mean SMS that will be processed directly by your app (given it has certain attention word) and will not go to the inbox i.e. no SMS notification on the phone
Since the two phones will, as you note, have changing IP addresses, you'll probably need to use an intermediary.
The general design pattern here would be to have a server with a fixed IP or DNS address that relays messages between your two mobile devices. The simplest implementation would be a webserver, to which each phone would connect via HTTP(S) to transmit data or poll for updates.
There are a number of backend-as-a-service platforms that provide this type of functionality pre-built, and would likely suffice for something like a chat system. Check out Cloudmine and Parse.
If you need a low-latency or near-realtime connection, you could also consider implementing your own server that uses the Android C2DM (Cloud to Device Messaging) service.
See Android's Sample Bluetooth Chat App, It will give you an idea for how it can be achieved.

GPRS Application using Java

We developed application written in Java/J2EE using which send and receives SMS from service provider and presently we are facing problem that there is some delay in messages and it cost's more for us.
by considering above situation we planned to move to GPRS technology (which is more cheaper and considerably fast).
So please suggest a course of action I can start with and post any sample application for GPRS-enabled system in Java.
With GPRS you would need a client application running in the mobile device. This means a lot of headaches for developing, deploying and supporting. Also, although it would be trivial for the clients to send messages, receiving won't be so straightforward. You would need to implement some kind of a "push" service. One of the problems would be that the client application should be always running.
In general, it isn't easy to replace SMS messages with GPRS communication. You may need to considerably change the architecture of your system.
To make a GPRS application using java you have to need GPRS Modem. First of all you have to make one container which handle request and replay of GPRS modem and your API. API contain private ip and port number wich send the request to container and container then send request to modelm and modem will give response to container and it send back to API.
By using methd Socket("IP Address", port number) you can connect with container and modem .
You have to need a public Ip Address andPort Number, it create virtual pipline between modem and container like as a telnet.
Using GPRS instead of GSM to send an SMS will not cause the SMS to be delivered any faster. You're barking up the wrong tree.

Categories

Resources