Sending commands from iPhone to Android - java

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.

Related

Can i host my ServerSocket or Java file somewhere on the web?

Heyy guys. I'm writing a chat application in java, works pretty well. But can i somehow host my Server file or the Serversocket on the web? I want to make it so my friends from other pcs can use the client and connect to the server file which is hosted on the web. Is that possible? Can i host the File/socket online?
When you run a java application that opens a ServerSocket, it opens a port on your local machine and starts listening for incoming connections. What you do with those connections is up to the implementation of the java code that you write.
The "web" is much less foreign than you are making it out to be. Your own computer can be on the web that you're talking about and people can connect to your chat service. Or you can choose to host it on something like an AWS server.
The following approach is assuming you are behind a pretty standard NAT config.
Once you run your java application, you need to make sure other computers can see you, either inside your LAN or outside on the internet. You want to start testing from as close to your computer as possible, then start expanding outward.
First you need to make sure that your computer's firewall is actually allowing connections on the port that your java application is listening on.
Opening ports in the Windows Firewall
Setting up and opening ports in Linux
Now computers on your LAN will be able to connect to your java program. Now you need to go one layer out, and port forward your router. This is much less standard so I can't help you too much, but Google can.
At this point, anyone on this internet, knowing your external ip and what port your java application is listening, can connect to your service.
If you chose to host this on an third party hosting service, you'll need to go through similar steps, but there may be slight differences that you can either ask about, or again Google is a great resource.

Uniquely connect an android application to a java applet on pc

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.

Client and Server socket connection

I'm new in java, and I have a problem. I have two android phones (Client and Server). Can anybody say me how to display on Client application the Server IP address?
Kryonet is a very good Java library which provides a clean and simple API for efficient TCP and UDP client/server network communication using NIO. It works on Android as well.
It will make your network programming work a lot more easier, and you can get a better understanding of how to write client and server side code.
I would suggest that you try out your network programming skills using this library.
You need not even hard code any IP address of the server while in LAN. The clients can discover the server in just one line of code.

networking in java for client server communication

I need to make a troubleshooting tool in java
From the java code, I need to communicate with tethereal (linux commands) to help me generate a .pkt file. The .pkt file will contain all the contents of the communication that took place between the client and the server- i.e. all the packet communication between the client and server.
how should I do that?
Do you know WireShark? That is a cross-platform Network Packet Capturing application.
The idea is that it captures all packets (TCP and UDP) that passes one network device (eg: WiFi card) and you apply a filter on the port that your application uses, and eventually an IP address. Very useful tool.
If you really need to do it in java you can use http://jnetpcap.com/ which is a wrapper for libpcap which works similar to tethereal.

Java Network Events

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.

Categories

Resources