[en] Android project (solved)

Topics: Technical Support
Jul 10, 2015 at 5:52 AM
Edited Jul 10, 2015 at 5:55 AM
Hi,

I have a project that I need to connect two android devices where one is the server and another is the client.

First off all, my version of Xamarin.Android is older, and I have to download your source code and compile to my current version.

For the server side, I think that the code is fine. No error was raised, but I don't know if it state is connected.

Here is the code for server and client: For simplicity, I have removed some non relevant code, but the app will be a server or client based on some settings.
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(RedNet.UI.Droid.Resource.Layout.RnUiBaseFragment);
            
            var _server = false
            if (_server)
            {
                        var _protocol = new TcpDuplexServerProtocolSetup(3500, new NullAuthenticationProvider(), true);
                        var _host = new ZyanComponentHost("SampleApp", _protocol);

                        _host.RegisterComponent<ISyncServerServices, SyncServerServices>();
            }
            else
            {
                        var _protocol = new TcpDuplexClientProtocolSetup(true);
                        var _connection = new ZyanConnection("tcpex://192.168.0.105:3500/SampleApp", _protocol);

                        var _services = m_Connection.CreateProxy<ISyncServerServices>();

                        Toast.MakeText(this, _services.RetornaNumeroConta().ToString(), ToastLength.Long);

            }

        }

Here is my interface/Class
    public interface ISyncServerServices
    {
        int RetornaNumeroConta();
    }

    public class SyncServerServices : ISyncServerServices
    {
        public int RetornaNumeroConta()
        {
            return 10;
        }
    }

Well, the questions and problems:
1) Is possible to launch the server on a Android device?
2) There is a way to know if the server is connected?
3) When the client try to connect on server, we get the error 10065 -> no route to host

I have tested the server on a windows forms app, but the same error occurs. Here in windows form version, I have used Zyan version from NuGet. (2.6)

In my tests, I have used one generic tablet with 4.2.2 android version and one Galaxy S4 with 4.4 android version.

Best regards...

Nelson Santos
Coordinator
Jul 10, 2015 at 10:50 AM
Edited Jul 10, 2015 at 11:46 AM
Hi Nelson,
 
1) Is possible to launch the server on a Android device?
 
Yes, absolutely. This is what Zyan Drench game does: one player starts Zyan-based server, and another player connects to it over Wifi network.
 
2) There is a way to know if the server is connected?
 
If the server doesn't throw any exceptions during the startup, then yes, it must be up and rinning, listening to the incoming connections.
 
3) When the client try to connect on server, we get the error 10065 -> no route to host
 
No route to host means that your client and your server use different networks.
For example, they are connected to different Wifi routers.
This error has nothing to do with Zyan, you still get the same error if you try to connect to, say, HTTP-server running on your tablet.

Make sure your server and client devices are connected to the same Wifi network.
Use Testing menu → Wifi information (dial *#*#4636#*#*) on your device to find out the IP address of your device.
Or display ZyanComponentHost.DiscoverableUrl via toast message after starting up the server.
It should detect the address you can connect to via the client (note: this feature is still experimental).

Regards, Alex
Coordinator
Jul 10, 2015 at 10:54 AM
One last thought: I see in your code that you start up your server in Activity.OnCreate method.
This way your server will be recreated every time you change the orientation of your device.
But it won't stop the server which is already running, so you'll get an error about your TCP port being used, and the application will crash.
Also, any non-top activity can be unloaded by Android when it needs more memory.
So don't start your server in your activities!
Jul 10, 2015 at 10:26 PM
Hi Alex,

Thank you for your fast reply!

I have discovered the reason that it not connect.

The two devices are on the same router, but my router has a flag on your configuration (Access Point Isolation) that block one device to communicate with others. This setting was enabled and blocked the access between the devices.

After disable this setting, work like a charm!

I have another question, but I will create another thread in case of others have the same question.

Clicking on "Mark as Answer" put this as solved? Can you guide me on how to do this?

And one more time, Thank you very much!!

Regards....

Nelson
Marked as answer by yallie on 7/10/2015 at 4:51 PM
Coordinator
Jul 11, 2015 at 12:51 AM
Edited Jul 11, 2015 at 1:04 AM
That's great!
You're welcome.

Regards, Alex
Oct 19, 2015 at 2:05 PM
Edited Oct 19, 2015 at 2:10 PM
Hi,

I have a connection problem between android as server and win client.

Android app is working with no problem.
host.DiscoverableUrl: tcpex://192.168.1.39:9010/MiniChat
But win client and android clients couldn't connect that service.
var _protocol = new TcpDuplexClientProtocolSetup(false);
var _connection = new ZyanConnection("tcpex://192.168.1.39:9010/MiniChat", _protocol);
An unhandled exception of type 'System.Runtime.Remoting.RemotingException' occurred in Zyan.Communication.dll

Additional information: Requested service not found (Zyan.Communication.IZyanDispatcher, Zyan.Communication, Version=2.6.0.0, Culture=neutral, PublicKeyToken=022216e8e71b6602). No receiver for uri MiniChat
Android: 4.2.2
Zyan : 2.6

Do you have any idea about my problem?

Regards.
Coordinator
Oct 29, 2015 at 4:00 PM
Hi flashkolik,

Looks like you are using Zyan version from Nuget...
It's a bit dated, and it may have bugs already fixed since then.
Please try building Zyan library from the latest sources and let me know if it helps.

Regards, Alex
Oct 30, 2015 at 2:53 PM
Hi Alex,

Thanks for your reply.

I solved my problem with removing "using" syntax.
using (var host = new ZyanComponentHost("MiniChat", protocol))
to
var host = new ZyanComponentHost("MiniChat", protocol)
Coordinator
Oct 30, 2015 at 7:19 PM
Ah, thanks for reporting that!

That explains everything.
Your server was only running within your "using" block, and then it was stopped and disposed of.

Regards, Alex.