 |

|
I am doing something similar, but with a c++ application. The device is communicating directly to a host PC which is listening for communication. How would one best add encryption to the application so that private data is not compromised? Just wondering if you've had any experience with this or can provide good ponters. I'm currently reading about the android side on their website, the next search would be for the pc application side.
|
|
|
|

|
Hi Cory,
This is quite a complex topic. So here is just a basic info you can use a starting point. I hope it will help.
In general there are two possibilities how to add encryption to the communication:
- Encryption is a part of the communication protocol e.g. if you use SSL or TLS.
- You encrypt data in yourself when you serialize the message.
Using SSL or TLS
SSL is a security protocol above TCP. It protects data from unauthorized access, unauthorized manipulation and verifies the identity of communicating parts. (If they are who they are saying they are.)
To establish SSL communication your service needs to have a digital certificate so that the client can verify if communicates really with the desired service.
Optionally, in case the server needs to be sure about identity of the client, the client may have its own certificate too.
Here is how the communication works (if only the server is certified):
- The client connects the server and asks for the digital certificate.
- The client verifies the received certificate (i.e. if the certificate is issued by a trusted authority, if the domain from the certificate matches with the domain sending the certificate, ...)
- The client creates a session key, encrypts it with the public key from the received certificate and sends it to the server.
- The server decrypts the session key from the client and uses it to encrypt the content for the client.
- The client uses the session key to decrypt the content from the server.
Using Serializer with Encryption
In this case, your application logic is responsible for the encryption. You encrypt the message when you serialize it before sending.
Basically you have two possibilities:
- Symetric Encryption - the same key is used for the encryption and decryption (e.g. AES algorithm). Depending on the particular communication scenario you may need to consider a safe mechanism how to tell service and all clients what is the key.
- Asymetric Encryption - encryption and decryption is realized via private and public keys which are related to each other. What is encrypted by the public key can be decrypted only by the corresponding private key and vice versa. Public key can be known to everybody and the private key is known only to its owner. E.g. RSA algorithm.
The Eneter framework supports both alternatives: SSL and also encryption via the serializer. E.g. you can check available serializers here (there are also short examples):
AES Serializer in Eneter for Java and Android
RSA Serializer in Eneter for Java and Android
(same serializers exist for Eneter for .NET too)
|
|
|
|

|
I appreciate the overview. It's been awhile since I've studied this topic. I have experience with the serializer methods you outlined from a project I did in school. It would be easier to me to just port it for my project than doing TLS. I guess I need to decide if I want to monetize this project, because if I do it seems better to do the hard work now and get SSL working.
|
|
|
|

|
Took me a minute to figure out what I was doing, but works very well. Thank YOU!
|
|
|
|

|
Hello Sir,
I developed one android application it sends data(username,password) to .net website.
But finding some difficulty in .net webservices. How .net werservices takes data and store into sql server database.Please explain or give some snippets of .net webservices that store data into sql server database which is coming from my android application.
my android code:
package com.example.webservicecalldemo;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
private ProgressDialog pd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pd = new ProgressDialog(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void callWebserviceClick(View v) {
String username = "testuser";
String password = "testuser";
new DemoWebserviceTask().execute(username, password);
}
private class DemoWebserviceTask extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
pd.setMessage("Please wait....");
pd.show();
}
@Override
protected String doInBackground(String... params) {
String username = params[0]; String password = params[1];
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://localhost:18747/new/uspassWebService.asmx");
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("password", password));
try {
httppost.setEntity((HttpEntity) new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = httpclient.execute(httppost);
if(httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = httpResponse.getEntity();
String result = EntityUtils.toString(entity);
return result;
} else {
return null;
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
pd.dismiss();
if(result == null) {
pd.setMessage("sending data failed");
pd.show();
return;
}
Log.d("Web-service-result", result);
}
}
}
Thanks.
|
|
|
|

|
I think your question and the code is not related to this article.
I would recommend to use stackoverflow forum to get answer for your question.
|
|
|
|
|

|
Hi
I built an app using Eneter (the server is written in java) and it works using the local IPs
The code it's the same as in your example, only I used the real "public" IP address instead of the local one.
But when I do that the library stops working, it fails to listen to the channel:
java.net.BindException: Cannot assign requested address: JVM_Bind
at java.net.DualStackPlainSocketImpl.bind0(Native Method)
at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
at java.net.PlainSocketImpl.bind(Unknown Source)
at java.net.ServerSocket.bind(Unknown Source)
at eneter.messaging.messagingsystems.tcpmessagingsystem.NoneSecurityServerFactory.createServerSocket(NoneSecurityServerFactory.java:32)
at eneter.messaging.messagingsystems.tcpmessagingsystem.internal.TcpListenerProvider.startListening(TcpListenerProvider.java:121)
at eneter.messaging.messagingsystems.tcpmessagingsystem.TcpInputChannelBase.startListening(TcpInputChannelBase.java:74)
at eneter.messaging.infrastructure.attachable.internal.AttachableDuplexInputChannelBase.attachDuplexInputChannel(AttachableDuplexInputChannelBase.java:38)
at DARCOServer.Messaging.MessagingManager.OpenConnection(MessagingManager.java:74)
at DARCOServer.MainClass.main(MainClass.java:36)
Any ideas?
|
|
|
|

|
I think the problem can be that some other process already listens to that adress and port.
E.g. an unterminated older run of your program.
Try to use the following command to see what processes are listening on which ports:
netstat -a -n -o
|
|
|
|

|
@1st answer: I believe the error message would be more specific if the port was already in use. This message seems to state java cant find the address, not a port. I might be wrong, though, and he should definately check. Here are a few other pointers:
@OP: Make sure you have a good grasp on networking basics about adressing, and eventually port forwarding. I understand your server works, while your client doesnt? Here are a few questions that might help:
-Are you sure your remote client is connected to the Internet (directly or via a local router)?
-Does your server really have a public address? Most of the time, you're behind a router which has the public address, and you have a private one. You might need to forward the requests on port TCP:XXX to your server. This is done directly in the router configurations.
|
|
|
|
|
|

|
1.Run NetService first.(I tried IP 127.0.0.1 and current IP).
2.Changed IP at net.client.
3.Run net.client. Simulator showed "Sorry! The application AndroidNetCommunicationClient(process net.client) has stopped unexpectedly. Please try again."
I debuged net.client. stoped at
private EventHandler<TypedResponseReceivedEventArgs<MyResponse>> myOnResponseHandler
= new EventHandler<TypedResponseReceivedEventArgs<MyResponse>>()
|
|
|
|

|
I am not sure if it is your case too, but this issue can also occur if the eneter library was not added to the project correctly.
Please make sure you added it this way:
Please be sure you added the library this way:
1. Right click on the android project -> New -> Folder, create folder libs
2. Right click on the android project -> Import... -> File System
3. In the section 'From directory' click 'Browse...' button and select directory with the eneter library
4. Select the eneter library in the list
5. In the section 'Into folder' click 'Browse...' and select your libs directory
6. Click 'Finish'
7. The eneter library should be now listed under 'Android Dependencies'
8. try to compile ans run your application
I hope this will help.
|
|
|
|
|

|
good example of the broad usage of this framework, it is awesome, a real alternative to WCF
|
|
|
|
|

|
The .Net side is up and running nicely.
I have all the framework, albeit it is version 4.2.0 whereas the code was written in 4.0.0
Have the latest SDK for Android and the Eneter jar referenced in the library
Checked the config xml to ensure internet access
Upon launching the code crashes Hard - critical failure in Main.
Any hint woudl be appreciated
|
|
|
|

|
Hi Bowlingball, your post does not contain details about the failure, so I could not investigate in detail.
But I guess the problem could be the eneter library was incorrectly added to the project and so you can build but when you execute it the application failes with errors indicating that something cannot be resolved.
Please be sure you added the library this way:
1. Right click on the android project -> New -> Folder, create folder libs
3. Right click on the android project -> Import... -> File System
4. In the section 'From directory' click 'Browse...' button and select directory with the eneter library
5. Select the eneter library in the list
6. In the section 'Into folder' click 'Browse...' and select your libs directory
7. Click 'Finish'
8. The eneter library should be now listed under 'Android Dependencies'
9. try to compile ans run your application
I hope this will help.
|
|
|
|

|
I added the library per your advice. Thanks, I did not use that method prior.
I have no errors, just 3 warnings in the AndroidManifest.xml in regards to 'no grammar constraints (DTD or XML schema) detected for the document.
I run and the emulator opens on port 5554.
It loads the 'HOME' successfully then sits there for 5 minutes and the console returns:
[2012-12-07 13:23:37 - Unexpected error while launching logcat. Try reselecting the device.] device not found
com.android.ddmlib.AdbCommandRejectedException: device not found
at com.android.ddmlib.AdbHelper.setDevice(AdbHelper.java:752)
at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:373)
at com.android.ddmlib.Device.executeShellCommand(Device.java:462)
at com.android.ddmuilib.logcat.LogCatReceiver$1.run(LogCatReceiver.java:110)
at java.lang.Thread.run(Unknown Source)
|
|
|
|
|

|
I've narrowed it down to 3 things:
a) the layout was/is not compatible with the latest SDK. I rebuilt it with the same fields as your example.
b)There is one portion of the code that are failing, causing an 'unfortunately, Androidnetcommunicationclient has stopped ' error
it is:
private EventHandler> myOnResponseHandler
= new EventHandler>()
{
@Override
public void onEvent(Object sender,
TypedResponseReceivedEventArgs e)
{
onResponseReceived(sender, e);
}
};
|
|
|
|

|
It is not quite clear from your post how the failure occurs (the exception stack would be very useful here).
There are 2 small issues I am aware of:
1. The onDestroy() method does not call super.onDestroy() what causes 'unexpected failure' error when closing the application. (I think that maybe this could be the problem you refer to.)
2. The openConnection() method is called from the main thread what causes the problem for Android 3.1 (Honeycomb) or higher where certain IO operations are not allowed from the main thread.
I have corrected both issues and updated the article. Please, feel free to download updated example. I hope it could help.
|
|
|
|

|
This version compiles to the emulator.
The Eneter groups sends 2 .jar files. You only need to import one of them. Importing both produces a DEX error.
Thanks for all the help. It is not talking to the service, but I'm sure that is an IP issue.
update: I set the IP address to the physical address of the machine, which is running the .net app and pay dirt. Works great.
Again thanks
|
|
|
|

|
I am glad it works for you.
If you had further questions feel free to ask.
|
|
|
|

|
Not sure if you receive the email I just sent. Please confirm
|
|
|
|

|
Yes, I had received e-mail from you regarding using in VB.
I am not an expert in VB but I will try to response.
|
|
|
|
|

|
I've copied your code but my android app won't send anything !! at least c# app won't show anything !!
what should I do ?!
I did put a breakpoint in onclick event but it seems that the event not firing at all , so my onclick event not working !!! why ?!!! any idea
thank you so much
modified 13-Nov-12 13:59pm.
|
|
|
|

|
Hi Seanmir,
Do you observe any exception?
The most common problem is related to using correct IP addresses. The example uses IP address suitable for the simulator. In case you try the example on a real device please be sure you use the real IP address of the machine where your .NET application is running.
It means, you must change the IP address in the .NET application from 127.0.0.1 to the network IP address of that machine. And then uou also must use the same IP address in your Android client application.
|
|
|
|

|
Thank you for your Reply ,
I solved my problem , the @override was the problem
private OnClickListener myOnSendRequestClickHandler = new OnClickListener()
{
@Override
public void onClick(View v)
{
onSendRequest(v);
}
};
I changed it to this
private OnClickListener myOnSendRequestClickHandler = new OnClickListener()
{
public void onClick(View v)
{
onSendRequest(v);
}
};
and now it's working perfectly , Thank you so much for your code
I'm trying to send string messages from android device to a .net app and .net app will sends back strings too . can you write any separate function for using in android , I mean just call a function for sending and receiving , like this :
private void Sendmessage(string message)
{
----
----
----
}
private String getmessage()
{
----
----
----
}
any help would be soooo helpful , thank you so much again.
|
|
|
|
|

|
Hi Ondrej
well done, all five of my.
|
|
|
|
|

|
It is beautiful and rare that a tutorial program runs without problems.
|
|
|
|

|
I am really glad I found it easy to use.
|
|
|
|

|
Thank you for the article
I have tested the the example you descripe using EClipse and sdk android 2.3.3
I always get the message "The application androidNetComunicationClient (process net.client) has stopped unexpectedly.Please try again"
I have tried every thing but i still get this message.
Please help me
With Regards.
|
|
|
|

|
I got that error too... where are we wrong?
I'm trying it on a Galaxy S2...
the compiler enforce me to remove @override in those statements
private void onResponseReceived(Object sender, final TypedResponseReceivedEventArgs e)
{
// Display the result - returned number of characters.
// Note: Marshal displaying to the correct UI thread.
myRefresh.post(new Runnable()
{
@Override
public void run()
{
myResponseEditText.setText(Integer.toString(e.getResponseMessage().Length));
}
});
}
private EventHandler> myOnResponseHandler
= new EventHandler>()
{
@Override
public void onEvent(Object sender,
TypedResponseReceivedEventArgs e)
{
onResponseReceived(sender, e);
}
};
private OnClickListener myOnSendRequestClickHandler = new OnClickListener()
{
@Override
public void onClick(View v)
{
onSendRequest(v);
}
};
}
Please help me...
|
|
|
|

|
This problem can occur in Eclipse if the java compiler level is not set to Java 1.6.
Please select your android project in Eclipse and open its properties.
Then ensure, Compliance compiler level is set to 1.6.
More info about this can be found also here:
http://stackoverflow.com/questions/4761888/override-annotation-error-android-prefs
http://stackoverflow.com/questions/3735661/bug-with-override-annotations-in-eclipse
http://stackoverflow.com/questions/1678122/must-override-a-superclass-method-errors-after-importing-a-project-into-eclips
I hope this will help.
|
|
|
|

|
Thank for your help... i didn't try your solution yet... but i surely do it soon! And i will post if it's successful... thank again
|
|
|
|

|
I would like to ask if this is the same issue as reported by mitnick902 (see bellow)
If it is not the same problem, could you please provide me more details?
|
|
|
|

|
when I try to .Net via C# I got these error lines
The type or namespace name 'TypedRequestReceivedEventArgs' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'IDuplexTypedMessageReceiver' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'Eneter' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'Eneter' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'Eneter' could not be found (are you missing a using directive or an assembly reference?)
|
|
|
|

|
Hello,
To be able to build examples you must download libraries from http://www.eneter.net/ProductDownload.htm[^] and add their references into the downloaded example projects.
Eneter for .NET in Visual Studio:
1. open the project
2. right click on 'References' and then choose 'Add References...'
Eneter for Android in Eclipse:
1. right click on the project and choose 'Properties'
2. click on 'Android' and add the library to the Reference|Project table bellow.
(Note: 'Is library' must stay unchecked.)
|
|
|
|

|
Hi Ondrej.
We have tested your SimpleTcp example. Works well!
Of course we played with the code and have tried to add features.
Like an second service on "server" side.
But it seems per service a single CreateDuplexInputChannel have to created as well. Is this right?
(Find below our enhanced implementation.)
Regards
Roberto
<pre lang="c#">
public class TestRequest
{
public int Id { get; set; }
public string Name { get; set; }
}
public class TestResponse : TestRequest
{
public bool Done { get; set; }
}
class Program
{
static void Main()
{
var aTypedMessagesFactory = new DuplexTypedMessagesFactory();
var aMessageReceiver = aTypedMessagesFactory.CreateDuplexTypedMessageReceiver<string, string>();
var aMessageReceiverTypedSolution = aTypedMessagesFactory.CreateDuplexTypedMessageReceiver<TestResponse, TestRequest>();
aMessageReceiver.MessageReceived += OnMessageReceived;
aMessageReceiverTypedSolution.MessageReceived += OnMessageReceive;
var aTcpMessaging = new TcpMessagingSystemFactory();
var anInputChannel = aTcpMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:8055/");
aMessageReceiver.AttachDuplexInputChannel(anInputChannel);
aMessageReceiverTypedSolution.AttachDuplexInputChannel(anInputChannel);
Console.WriteLine("TCP service is running. To stop press ENTER.");
Console.ReadLine();
aMessageReceiver.DetachDuplexInputChannel();
aMessageReceiverTypedSolution.DetachDuplexInputChannel();
}
private static void OnMessageReceived(object sender, TypedRequestReceivedEventArgs<string> e)
{
Console.WriteLine("Received message: " + e.RequestMessage);
var aResponseMessage = "Thanks for " + e.RequestMessage;
var aReceiver = (IDuplexTypedMessageReceiver<string, string>) sender;
aReceiver.SendResponseMessage(e.ResponseReceiverId, aResponseMessage);
}
private static void OnMessageReceive(object sender, TypedRequestReceivedEventArgs<TestRequest> e)
{
Console.WriteLine("Received message: " + e.RequestMessage.Name);
var aReceiver = (IDuplexTypedMessageReceiver<TestResponse, TestRequest>)sender;
aReceiver.SendResponseMessage(e.ResponseReceiverId, new TestResponse{Done = true, Id = e.RequestMessage.Id, Name = e.RequestMessage.Name});
}
}
|
|
|
|

|
Hi Roberto,
You have two possibilities how to create a service processing multiple requests:
Alternative 1: Multiple channels
You will create multiple DuplexTypedMessageReceiver and to each one you will attach a different duplex input channel. Each duplex input channel must listen to a different port.
using System;
using Eneter.Messaging.EndPoints.TypedMessages;
using Eneter.Messaging.MessagingSystems.MessagingSystemBase;
using Eneter.Messaging.MessagingSystems.TcpMessagingSystem;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
IMessagingSystemFactory aTcpMessaging = new TcpMessagingSystemFactory();
IDuplexTypedMessagesFactory aReceiverFactory = new DuplexTypedMessagesFactory();
IDuplexTypedMessageReceiver<int, string> aReceiver1
= aReceiverFactory.CreateDuplexTypedMessageReceiver<int, string>();
aReceiver1.MessageReceived += OnReceiver1_MessageReceived;
IDuplexInputChannel anInputChannel1
= aTcpMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:8055/");
aReceiver1.AttachDuplexInputChannel(anInputChannel1);
IDuplexTypedMessageReceiver<string, int> aReceiver2
= aReceiverFactory.CreateDuplexTypedMessageReceiver<string, int>();
aReceiver2.MessageReceived += OnReceiver2_MessageReceived;
IDuplexInputChannel anInputChannel2
= aTcpMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:8056/");
aReceiver2.AttachDuplexInputChannel(anInputChannel2);
Console.WriteLine("Service is listening. Press enter to stop.");
Console.ReadLine();
aReceiver1.DetachDuplexInputChannel();
aReceiver2.DetachDuplexInputChannel();
}
static void OnReceiver1_MessageReceived(object sender, TypedRequestReceivedEventArgs<string> e)
{
IDuplexTypedMessageReceiver<int, string> aReceiver
= (IDuplexTypedMessageReceiver<int, string>)sender;
aReceiver.SendResponseMessage(e.ResponseReceiverId, 12345);
}
static void OnReceiver2_MessageReceived(object sender, TypedRequestReceivedEventArgs<int> e)
{
IDuplexTypedMessageReceiver<string, int> aReceiver
= (IDuplexTypedMessageReceiver<string, int>)sender;
aReceiver.SendResponseMessage(e.ResponseReceiverId, "12345");
}
}
}
Alternative 2: One channel
If you prefer to route all requests via one IP address and port you can use components DuplexChannelWrapper (on client side) and DuplexChannelUnwrapper (on server side).
So, the client would have multiple DuplexTypedMessageSender connected via channels to the DuplexChannelWrapper. And the service would have DuplexChannelUnwrapper listening to one IP address and port and routing incoming messages to matching DuplexTypedMessageReceiver.
I am going to write a separate article about this topic with an example for Android and .NET.
You also can check one of my previous articles showing this scenario (it is only for .NET but the implementation for Java (Android) will be same):
How to Implement Service Receiving Requests via Messages[^]
|
|
|
|

|
Hi Ondrej.
Ok. I will check this ans think about.
Will come back later, sure with some new questions
Regards
Roberto
|
|
|
|

|
How to communicate in real situation through WiFi between android mobile device and comuter (especially concerning addresses of devices) ? Thank You, jirkaM.
|
|
|
|

|
Yes, the real situation requires using real IP addresses.
It means, the following line in the service code must be replaced with the real IP address and port the service is using.
IDuplexInputChannel anInputChannel =
aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:8060/");
Then you also need to use the correct IP address in your Android client application. You must replace the following line with the same real IP address and port as used in the service.
IDuplexOutputChannel anOutputChannel =
aMessaging.createDuplexOutputChannel("tcp://10.0.2.2:8060/");
The communication scenario described in this article does not require to know the IP address of the cell phone device.
When you have set correct addresses the communication between real Android device and service should be same as described in the article.
|
|
|
|

|
I want to connect Android device to desktop via USB and without WiFi?
What IP addresses (and ports) should I set in that case in both modules?
|
|
|
|

|
Hi Dragpre,
The communication via the cable is not so straight forward as using WiFi.
The problem is, the communication via the cable involves Android Bridge running on PC that must be configured and there is also a technical limitation that the android device must be a service when communicates via the cable.
Android Bridge
Android Bridge is the application that starts on your PC once your device is connected via the cable (There is adb.exe process in Task Manager).
On the other side of the cable (in the Android device) is running Android Bridge Daemon (process adbd).
The sequence for the communication via the cable looks like this:
- Your desktop application sends the message to the Android Bridge via TCP.
- Android Bridge (adb.exe running on PC) receives the message and using some internal protocol sends it via the cable to the Android device.
- Android Bridge Daemon running on the device receives the message and forwards it via TCP to the listening Android application.
- Android application processes the message and can send back a response message.
Technical Limitation
The technical limitation for communication via the cable is the Android device must be a service. It means, the android cell-phone must be a listener serving requests from the PC.
Please notice, it is exactly opposite as in the example from my article where the Android application is the client. You must use 'MessageReceiver' and 'DuplexInputChannel' in the Android application to listen to messages.
Example how to do it
If you want to setup the communication via the cable you must:
- Implement your android application as the service. It means your android application must be the listener receiving messages. Duplex input channel must listen to 127.0.0.1 (loopback in the phone) on the port you will choose e.g. 8090. Therefore the address will be: tcp://127.0.0.1:8090/
- You must implement your desktop application as the client sending messages to 127.0.0.1 (loopback in PC) and again you can choose your own port. E.g. you can use the same port 8090. Therefore the address the client will use for the communication will be tcp://127.0.0.1:8090/.
- You must configure Android Bridge to forward messages to the Android device. You can use for this the following command.
adb forward tcp:8090 tcp:8090
(you can find adb.exe on the following path: c:\Program Files\Android\android-sdk\platform-tools\adb.exe)
It tells Bridge that adb.exe shell listen to the port 8090, then forward it via the cable to the device and then inside the device forward it again to the port 8090.
So here is the summary how the communication will look like for our example:
- Desktop client application sends a message to 127.0.0.1:8090.
- adb.exe running on PC receives the message on 127.0.0.1:8090 and forwards it via the cable to adbd.
- adbd running on the device receives the message and sends it to 127.0.0.1:8090.
- android application listening to 127.0.0.1:8090 receives the message.
I hope my answer will help.
(Maybe I could write another article explaining the communication scenario via the cable in detail.)
|
|
|
|
 |