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.
Related
I'm looking for some protocol for pairing device based on esp8266 with mobile app. I know i can write Android app using JAVA, build an RARP table, read the IP comparing physical address of the esp8266 and connect to it directly using TCP, since i can put esp8266 into server mode, but i cannot find a way to build RARP table in codename one because java.net.* are not supported. I was looking for other protocols, but found nothing supported yet. Do you have any suggestions? Let me admit that esp8266 IP has to be dynamic.
We have Socket but it doesn't support broadcast. For that you will need to use native interfaces and can use java.net on Android. On iOS you will need to use the native iOS API's to do that.
See this tutorial on using native interfaces: https://www.codenameone.com/how-do-i---access-native-device-functionality-invoke-native-interfaces.html
I have been trying to find a way within my android application to determine which app is requesting a connection to the internet (or more formally establishes a TCP connection). Here is an application which already does that.
The above app determines all connections independently without the need of rooting the phone and only with the "Full network access" permission which is magnificent.
I am currently developing with the help of this source, a proxy server on android and I can easily read the connections the phone establishes over the Internet.
How do I determine which application is actually requesting the specific TCP (http/https) connection?
I came in contact with Peter, a developer of the mentioned application and he was very kind to provide an answer regarding in discovering connections.
Here is his answer:
You can find the network information in the standard kernel proc files, like in any other Linux distribution:
/proc/[pid]/net/tcp
/proc/[pid]/net/tcp6
/proc/[pid]/net/udp
/proc/[pid]/net/udp6
/proc/[pid]/net/raw
/proc/[pid]/net/raw6
The [pid] is the process id of your app, but each file holds information about all network connections for the corresponding protocol.
I add some detail to my question.
I receive on my Xbee device a flow of GPS coordinates but I'm unable to read and stock these data on a buffer.
My Xbee device is connected to my laptop on a usb serial port, that's why I want to create a program java to read and use my data flow sending by the serial port.
I'm searching on internet some code example or tutorials , without enought advices for my understanding, or I just find some dead projects.
I found that it's possible to use jssc library or javax.comm (but I can't download the javax.zip on sun). Do you know an other better USB API ? Could you help me to understand how I can manage to read and stock my Flow of GPS cordinate ?
Forget abut USB, it acts as transparent bridge. What you need is a way to read from the serial port. javax.comm is not (officially) available any more. I have been successfull dealing with the arduino serial port with the RXTX library.
First make sure you see the serial port on your dev machine. This might require to install a driver. Then use a terminal program to connect to the serial port.
Once this is working go on and get RXTX working.
Just in case: You can have only one connection at a time. Make sure that only one of IDE, terminal programm and RXTX is connecting to the serial port at the same time.
What method could I use to login to a Cisco or Juniper routers? I know I can use telnet to make a connection to the router itself but I am not aware of an API or anything that allows me to login non-interactively. So how could I do this?
Are there any libraries I can use to achieve this?
I have seen people use scripts that implement things like expect to know when to send the username and the password. But that is for shell scripting. How can I do this in java? I would prefer to keep strictly in java too.
The goal of this is allow a java program login into a router so I can query the router for interface states and execute commands on the router.
Any ideas?
You need to use some Java library for doing the same. http://www.pitman.co.za/projects/jssh/ is a good Java SSH client. http://commons.apache.org/proper/commons-net/ has a good telnet implementation
As far as extracting information, you should be able to do it by using SNMP to query the router. Pretty much everything is available over SNMP. Now, as far as command execution, there are SNMP set commands used to "write" information to a router, but you will need to look into that more carefully as I doubt the full command set can be replaced with SNMP set commands.
For Cisco, find out what the IOS image filename is for your device, then you can get the MIB file here: http://tools.cisco.com/Support/SNMP/do/MIBSupport.do?local=en&step=3. Review the MIB file and you will see what is available via SNMP for that device.
You should be able to do something similar for Juniper on their site.
Now, I don't know much about Java, but I do know that there are SNMP libraries available for it (like http://www.snmp4j.org/ ).
With that you will not need to worry about logging into the router, or about any interactive stuff.
Note that, in the case of Cisco, it's common to connect using a serial port on a PC directly into the service port on the router. This connection uses a programming protocol called IOS.
The easiest way to utilize this is with a programming language called expect. This name describes the language in that you expect to get a prompt from the port and then you respond. Sending that message (your response), you expect to get another response, to which you respond, ad completum - my term ;)
Note that this cable is proprietary to Cisco, I'm sure there are pin-outs available though.
Finally, it would be possible to emulate this program on java, via a serial port library.
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.