I am creating a java mobile application and I want to be aware as to when the device obtain an IP address to then be able to send messages to a backend system.
Do any API exists? I guess if an API existed it would have to use system dependant calls thru JNI?
Thank you,
Julien.
OK, I'm not 100% sure I understand what you are trying to do but here are a few things that could prove useful:
stackoverflow has tags for J2ME and javaME, the mobile versions of Java.
Theorically, installing a MIDlet that declares a static PushRegistry socket connection could force the device to always have an IP address. That would obviously depend on how the Pushregistry spec was interpreted by the VM provider.
There is no standard JNI support for mobile Java virtual machines.
A mobile Java application may be automatically paused when it is backgrounded so I'm not convinced you shouldn't just use the GCF API to open a client socket connection to your back-end system. It is presumably only needed when the MIDlet is in the foreground.
Related
I am working on an application where I need to establish a server on a Windows/Linux/Mac machine which will need to communicate to an Android/iOS device over an existing WiFi network.
I am just in the research phase for now, and though I can find answers for communicating between PC-Android, PC-iOS, Mac-iOS etcetera, I cannot find an answer using which I can do all of it.
The mobile application will be different for both the platforms, of-course, but the server application should ideally be the same, and should be cross-platform.
I should also mention that the server and the clients(mobile-apps) will maintain a 1:n relation, meaning that several Android/iOS devices will be communicating with the server at once.
I need advice on which language/library shall I use for the server which would let the it communicate to both the mobile platforms.
Advice on the libraries I should use for the mobile platforms will also be helpful, though it's not important until I complete the server.
I am just looking for links to helpful resources, though I will be very grateful if you share some code.
I shall also mention, I know Python/Java/C++ which I can use for the server, but you are open to suggest another language which may make the work easier.
EDIT: What I forgot to mention is that, this will be a local server, that is, it needs to communicate with these devices on a LAN (devices on the same wifi network).
If you Know Java for the server side you cab create an application that hosts a RestFull API running on a tomcat server that you call with a local address (such as http://ip_adress:port/appname)
Tomcat can run on Windows, Linux or Mac.
If you need more informations just ask
I want to connect my android application to an applet which is running on my pc on Google chrome on Wi-fi.. where my phone works as a wi-fi hotspot and pc as the connected device. I want the connection to work uniquely as I want commands to be passed from my application to the specific applet, on the execution of which my applet does specific tasks. Please tell me the APIs which I can look in both Java and Android or the technology I have to use to make it work..
You need to use any program, such as wamp server, to make your computer to be a localserver. It will install PHP 5, MySQL and Apache. In other hand, you will also need a little bit of knowledge in Php language to create you own web services.
Another thing you need to be aware is that to handle you connection between server and device (and by this I mean which IP you are going to use) you will have a little headache; but first things first..break your problem in little parts thus will be easier to solve them.
I recommend this tutorial.
I think the simple way to connect these two softwares is using UDP.
It is fast, it is easy to program but it is generally unreliable according to TCP. But it is already local network. I dont think that is a case you need to take care in your local wifi network.
So take a look at this tutorial http://tutorials.jenkov.com/java-networking/udp-datagram-sockets.html
There are other ways like https://www.alljoyn.org/. It has more functinality but more complicated.
You must install Server on your PC(Apache httpd or apache tomcat or other based on your interest). A server listens to request from clients. When your mobile is connected to your pc(doesn't matter wire or wireless), you can make a request to an url(say, localhost:8080/welcome) from your app.
Create an applet and connect it with your web application(in the server) using java.net.URL and java.net.URLConnection.
On performing some operation on the client, call the url of the server application and forward the response to the applet.
I have a code running in router that sends UDP packets(using Sendto() function and a string of data) to a particular server whose IP address and port number I will mention in my code.
I want to deploy a server application that could receive a UDP packet and store its information on server or somewhere else not sure right now.
I have decided to use Google app Engine for hosting my server side code which most probably will be having something like recvfrom() function to receive string.
So how and by using what API's can I start developing my server side code.
Google App Engine has a Preview release of a Socket API, but it does not let you create listening sockets. See Limitations and restrictions section at https://developers.google.com/appengine/docs/python/sockets/
You cannot create a listen socket; you can only create outbound sockets.
You can use Google Compute Engine to run any reasonable software on Google's cloud platform, including programs that receive UDP datagrams. You must always pay for Compute Engine instances.
According to the newest edition of App Engine Socket docs for Java, if you're using java 8 runtime you should be able to use java sockets without limitations:
Applications in the Java 8 runtime default to using native Java
sockets with no restrictions: Google recommends that you keep this
default.
That means that it should be possible to use java.net.DatagramSocket or java.nio.channels.DatagramChannel freely to work with UDP.
I need to send some commands using the wireless network from an iPhone application to an Android application. I thought a possible way would be to send the commands as strings over TCP (SOAP seemed a better solution, but it seems some libraries would be necessary and it is not necessary). Is there anyone out there who can address me to some documents or some place to start this kind of applications?
Thanks!
The simple answer to this question is that you need to listen on a specific port number by opening a Server Socket on the Android side, and from the client side (iPhone) open a socket connection towards the Android's IP address and port.
Luckily sockets are a pretty standard thing nowadays and behave typically the same across operating systems, that is Linux, Windows, Mac OSX, and iPhone iOS, Android and Symbian.
The only difference you have is which programming language you need to use. On Android you have to use Java. So if an Android application is waiting for the connection your application needs to open a ServerSocket and listen of incoming connections.
From the iPhone part, your application needs to be developed in Objective C. Nothing fundamentally different, but the programming language is different.
How do I make a J2ME Midlet to communicate with a java program or some application on the pc through the cable connected?
Incredible_Honk is almost right. The key is to use the (standard) system property "microedition.commports". This provides a comma delimited list of the com ports which are available to your application. To open a connection use CommConnection as follows:
CommConnection con = (CommConnection) Connector.open("com:<commport name>");
Usually this will provide access to a USB serial connection, possibly also infrared if available. Iterate through each one to see which one corresponds to the connection you're looking for.
On Windows at least, you will need to install the correct drivers for your handset first. This will then allow you to open a serial connection and communicate with the application.
There is no general way of doing this. It hardly depends on the capabilities of the mobil. Might be that there is some vendor API giving you special access to USB, but I'm not aware of any.
Some phones support communication via serial port connections.
Take a look at the javax.microedition.io.CommConnection interface for more information.
Sonyericsson phones offer a way to debug your midlet on the device and get the console messages back through the cable.