Search code examples
c#androidtcpiploopback-address

Android to PC TCP communication working only on Emulator


I have a requirement to implement an android application to communicate with a c# application on a PC over TCP (wifi). I have followed this -

https://workspaces.codeproject.com/dhl_hh/android-how-to-communicate-with-net-application-vi

tutorial to implement the solution which uses the eneter library.

This works just fine on the emulator as the IP used for C# application is

IDuplexInputChannel anInputChannel
            = aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:8060/"); 

and the IP used for the Android app is

IDuplexOutputChannel anOutputChannel
        = aMessaging.createDuplexOutputChannel("tcp://10.0.2.2:8060/");

However, when i transfer the android app to actual device and try to transmit data over wifi the C# application does not display the string transferred from the mobile device as shown in the tutorial.

The fixes I tried was,

  • Kept the C# IP as is (127.0.0.1) and changed the android IP to PC's IP (192.168.137.1) where the c# app is running.
  • The fix that works : Changed the C# IP to the PC's actual IP (192.168.137.1) and changed the IP address of the android app to the actual IP of the android device (192.168.137.1).
  • FYI : I did not change the port number

These fixes did not fix the issue and I have no clue on how to do this. I was trying many solutions for few days now as I am a novice to the filed of tcp programming.

I would really appreciate you experts advice on how to fix this issue.

You help s greatly appreciated :)

Thanks in advance.

PS

  • Actual IP of PC (with the C# program) - 192.168.137.1
  • Actual IP of the android device (with the android app) - 192.168.137.14

Logcat output

05-29 12:49:17.988: E/EneterMessaging(1792): ~  1 eneter.messaging.endpoints.typedmessages.DuplexTypedMessageSender.sendRequestMessage DuplexTypedMessageSender<MyResponse, MyRequest> atached to the duplex output channel '' failed to send the request message because it is not attached to any duplex output channel.
05-29 12:49:17.988: E/EneterMessaging(1792): ~  1 net.client.AndroidNetCommunicationClientActivity.onSendRequest Sending the message failed.

05-29 12:49:17.988: E/EneterMessaging(1792): Exception:

05-29 12:49:17.988: E/EneterMessaging(1792): java.lang.IllegalStateException: DuplexTypedMessageSender<MyResponse, MyRequest> atached to the duplex output channel '' failed to send the request message because it is not attached to any duplex output channel.

05-29 12:49:17.988: E/EneterMessaging(1792): eneter.messaging.endpoints.typedmessages.DuplexTypedMessageSender.sendRequestMessage(DuplexTypedMessageSender.java:67)

05-29 12:49:17.988: E/EneterMessaging(1792): net.client.AndroidNetCommunicationClientActivity.onSendRequest(AndroidNetCommunicationClientActivity.java:120)

05-29 12:49:17.988: E/EneterMessaging(1792): net.client.AndroidNetCommunicationClientActivity.access$1(AndroidNetCommunicationClientActivity.java:111)

05-29 12:49:17.988: E/EneterMessaging(1792): net.client.AndroidNetCommunicationClientActivity$2.onClick(AndroidNetCommunicationClientActivity.java:160)

05-29 12:49:17.988: E/EneterMessaging(1792): android.view.View.performClick(View.java:4102)

05-29 12:49:17.988: E/EneterMessaging(1792): android.view.View$PerformClick.run(View.java:17084)

05-29 12:49:17.988: E/EneterMessaging(1792): android.os.Handler.handleCallback(Handler.java:615)

05-29 12:49:17.988: E/EneterMessaging(1792): android.os.Handler.dispatchMessage(Handler.java:92)

05-29 12:49:17.988: E/EneterMessaging(1792): android.os.Looper.loop(Looper.java:155)

05-29 12:49:17.988: E/EneterMessaging(1792): android.app.ActivityThread.main(ActivityThread.java:5520)

05-29 12:49:17.988: E/EneterMessaging(1792): java.lang.reflect.Method.invokeNative(Native Method)

05-29 12:49:17.988: E/EneterMessaging(1792): java.lang.reflect.Method.invoke(Method.java:511)

05-29 12:49:17.988: E/EneterMessaging(1792): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)

05-29 12:49:17.988: E/EneterMessaging(1792): com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)

05-29 12:49:17.988: E/EneterMessaging(1792): dalvik.system.NativeStart.main(Native Method)

05-29 12:49:17.988: E/EneterMessaging(1792): ==========

Solution

  • The Windows Firewall should be configured to allow that connection or turned off.