 |

|
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:59.
|
|
|
|

|
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.)
|
|
|
|

|
First of all let me congrats you for your article, might be useful in the future. My question is, there any way to connect an Android app to any other PC program through synchronization? If there is, what topics, books or websites should I check? Thanks.
|
|
|
|

|
Hi Chaq686, I am not sure if I understand your question. Could you please e-mail me more details about your communication scenario?
I will try to support you.
|
|
|
|

|
Basically is doing the same thing, but through USB cable instead of TCP/IP.
|
|
|
|
|

|
first The IP address 127.0.0.1 (loopback) cannot be used for communication between the Android emulator and the .NET application!
this is not true ... you can use 127.0.0.1 on PC ... but on android ... on android you should first you read documentation: Network Address Space(android emulator)[^]
anyway:
Duplex means that we can send messages from both sides, right? Ok, so it keeps TCP connection alive. And now we come to real question: should we use wake lockcs[^] to keeps this connection online(and drain battery in few hours)? Another option is: don't use this lib on Android platform at all and take advantage of C2DM and use some stateless connetion(like http/https) for communication.
...works fascinates me...i can stare it for hours...
|
|
|
|

|
Hi Selvin, thanks for your comment regarding the IP address. It is a valid point and I will update the article.
Regarding the second part of your response. I think it is a matter of the application design how long the connection stays open. For many communication scenarios it is probably possible to design it the way the connection does not need to stay open for hours - eneter library allows users to open/close connections as needed.
E.g. In case of a typical request-response scenario, the client can open the connection only for necessary time ...
The C2DM framework is an interesting project but it is not designed to transfer a lot of user content. It is intended just to let the client know there is some content on the server. The application should then connect its server and make its own communication to get the content. It has quotas related to number of messages you can send and the maximum size of the message (I think 1024 bytes). The communication depends on the Google server. => C2DM is a different thing focusing on a certain scenario.
|
|
|
|

|
It's a very good article!
I have a question about license.
What is the license of "Eneter Messaging Framework"?
Can I use it in my project?
|
|
|
|

|
I am glad you like the article.
The framework is free for non-commercial use. For more details you can refer here.
|
|
|
|

|
What did you use to create that beautiful illustration at the top of the article showing the communication channel between Android and .NET?
|
|
|
|

|
The illustration was created in Adobe Illustrator. I am glad you like it .
|
|
|
|
 |