[en] Problem with Event: Server (Windows) -> Client (Android 5.0.1)

Topics: Technical Support
Feb 25, 2015 at 2:53 PM
Edited Feb 25, 2015 at 3:09 PM
I took the example MiniChat and did a simple Android version of the client project.
MiniChat

I start the server from MiniChat project and connect 2 windows client (example code) and 1 android client (my code).

When sending messages from windows client 1 or 2 those 2 clients and the server are receiving the event but not the android client.

Furthermore, when I send a message from the android client weird things start happening : the first message is correctly received by the server and 2 clients but after that the 2 clients aren't receiving anything until I disconnect the android client from the server.

With 3 clients they are receiving 2 messages and then nothing until android is disconnected.

The event is "MessageReceived" in the shared project "Zyan.Examples.MiniChat.Shared" in IMiniChat.cs
public event Action<string, string> MessageReceived;
Android code :
TcpDuplexClientProtocolSetup protocol = new TcpDuplexClientProtocolSetup(true);
Connection = new ZyanConnection(serverUrl, protocol, Credentials, false, true);
...
_chatProxy = Connection.CreateProxy<IMiniChat>();
_chatProxy.MessageReceived += new Action<string, string>(_chatProxy_MessageReceived);
...
private void _chatProxy_MessageReceived(string arg1, string arg2)
{
    etChat.Text += string.Format("{0}: {1}\n", arg1, arg2);            
}
Is there anything special that need to be configured to send event from window to android?

Thanks
Marc-Andre
Coordinator
Feb 25, 2015 at 5:38 PM
Hi Marc-Andre,
 
Is there anything special that need to be configured to send event from window to android?
 
No, nothing special needs to be configured.

What version of Zyan are you using?
Does the Android client reference the same version of Zyan as Windows server?
Are there any Zyan-related exceptions within Xamarin Studio or Visual Studio's output windows?

Regards, Alex
Feb 25, 2015 at 6:30 PM
Hi Alex,

I am using the Zyan's version 2.6.0.0 on all 3 project.
There is no exceptions in the output of Visual Studio.

I am also using a real cellphone (Nexus 6 with Android 5.0.1) to tests.

Thanks
Marc-Andre
Coordinator
Feb 26, 2015 at 9:56 AM
Hi Marc-Andre,

could you please zip and upload your solution somewhere?
Hope the bug will reproduce on my Android 4 phone.

Regards, Alex
Feb 26, 2015 at 12:51 PM
Hi Alex,

Sure there you go : link

Thanks
Marc-Andre
Coordinator
Feb 26, 2015 at 11:07 PM
Hi Marc,

with a couple of minor modifications it works on my noname Android 4.0.3 phone.
First, I converted MiniChat.Shared into portable library.
Second, I added RunOnUiThread to the event handler in your activity:
private void _chatProxy_MessageReceived(string arg1, string arg2)
{
    RunOnUiThread(() =>
    {
        etChat.Text += string.Format("{0}: {1}\n", arg1, arg2);            
    });
}
And here it is — Windows server and clients:
Windows

Android application:
Android

I'm going to upload the updated solution in a couple of minutes, stay tuned.
Coordinator
Feb 26, 2015 at 11:19 PM
Download the updated solution here: Marc-Andre-MiniChat.zip

Regards, Alex
Feb 27, 2015 at 1:59 PM
Edited Feb 27, 2015 at 2:43 PM
Hi Alex,

Nothing is happening when I tried with these modifications on Android 5.0.1. Changing the compile android version to 5.0 doesn't seem to change anything either.

EDIT: We tried on a phone with 4.1 and it's working just fine. The issue seems to be with 5.0.1.

Thanks
Marc-Andre
Coordinator
Feb 27, 2015 at 4:51 PM
Hi Marc,

what version of Xamarin are you using?
Please try updating to the most recent version first.
I've had problems with my Zyan Drench application due to an incompatibility of my old version of Xamarin.Android with Android 5 ART runtime.

Unfortunately, I haven't got an Android 5 device to experiment with.
I'm going to try running yout application on emulator once I'm back from my vacation, but emulator is not quite representative...
An application which works fine on emulator might not always work on a real hardware.

Regards, Alex.
Feb 27, 2015 at 6:10 PM
Hi Alex,

I am currently using the Version 5.7.1 (build 17) of Xamarin.
Their is no available update.

Thanks
Marc-Andre
Mar 5, 2015 at 8:20 PM
Edited Mar 5, 2015 at 8:21 PM
Hi Alex,

After taking the source code and using it into the project instead of the Zyan.Communication.dll the chat on android 4.1 wont received any message.

The cause seems to be that the Delegate in the event MessageReceived is null on the server when using the the source code but with the dll the delegate is not null even if the execution of HandleEventSubscription looks fine in ZyanProxy.cs.
    public class MiniChat : IMiniChat
    {
        public event Action<string, string> MessageReceived;

        public void SendMessage(string nickname, string text)
        {
            ServerSession session = ServerSession.CurrentSession;
            Console.WriteLine(string.Format("[{0} IP={1}] {2}:{3}", 
            DateTime.Now.ToString(), session.ClientAddress, session.Identity.Name, text));

            if (MessageReceived != null)
            {
                try
                {
                    //here the delegate is null
                    MessageReceived(nickname, text);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
    }
Coordinator
Mar 5, 2015 at 10:45 PM
Edited Mar 5, 2015 at 11:07 PM
I am currently using the Version 5.7.1 (build 17) of Xamarin.
Their is no available update.
 
So it doesn't look like a known bug of Xamarin.Android...
Too bad I haven't got an Android 5 device to investigate this.
 
After taking the source code and using it into the project instead of the Zyan.Communication.dll the chat on android 4.1 wont received any message.
 
That's very strange. The behavior should be exactly the same as with the compiled dll.
Latest SVN version has no changes compared to the release build.

What C# compiler are you using to build the solution?
Is it Microsoft C# or Mono's MCS? What version is it?
I used Microsoft C# 2010 v.4.0.30319.34209 for building the Nuget package.

What build configuration for Zyan project is active, Debug or Release?
What exact project is it, Zyan.Communication, Zyan.Communication.Fx3 or Zyan.Communication.Fx4?

Please upload your solution ZIP file, as earlier.

Thanks, Alex
Mar 6, 2015 at 1:09 PM
Edited Mar 9, 2015 at 7:51 PM
Build Configuration : Debug
Project : Zyan.Communication

The project is the exact same that you uploaded but with the reference to the source code.

I am not sure about the compiler version, I used Visual Studio 2013 with .NET Framework Version 4.5.50938
Here

The source code we used instead of the dll was Zyan.Communication.Android for the chat and not on the server.


EDIT: After multiple tests the only device that is not working is the Nexus 6 with 5.0.1 its working on the Nexus 5 with 5.0.1 and the MotoG (2013) 5.0.2.
It's also working with the emulated version of a Nexus 6 5.0.1

Thanks
Marc-Andre