[en] Zyan Fires event on only a single client

Topics: Technical Support
Jan 21, 2013 at 12:48 AM

I have begun creating a chat application, when I run many chat clients, Server fire event on only the last run client. I write it using the windows form not a console app. Please help me.

Coordinator
Jan 21, 2013 at 6:02 AM

Hi specialnas,

which version of Zyan do you use?

Can you post a snippet of your source code?

Have you checked out the MiniChat example? This is tiny but a fully working chat application created with Windows.Forms and Zyan.


Regards,
Rainbird

Jan 22, 2013 at 12:47 AM

I use Zyan 2.4. I already checked the MiniChat example. Everything looks the same.

I have 3 projects. They are server, client, and the library. In library I have one interface. Here is my interface source code.

    public interface IEZChat

    {

        void RegisterName(String Name);

        event Action<String> NameRegistered;

    }

 

I have another implement class. Here is its code.

class ChatService : EZChatLibrary.IEZChat

    {

        private Hashtable _NameList = new Hashtable();

        public void RegisterName(string name)

        {

            if (!_NameList.ContainsKey(name))

            {

                _NameList.Add(name, name);

                if (NameRegistered != null)

                {

                    NameRegistered(name);

                }

            }

        }

 

        public event Action<string> NameRegistered;

 

    }

I have another static class to run the server.

public static class EZChatServiceRunner

    {

        public static void Run()

        {

            ZyanComponentHost host = new ZyanComponentHost("EZChat", 9999);

            host.RegisterComponent<IEZChat, ChatService>(ActivationType.Singleton);

        }

 

    }

 

I have another static class to create proxy object at client.

public static class EZChatClientProxy

    {

        public static IEZChat CreateProxy()

        {

            ZyanConnection connection = new ZyanConnection("tcp://192.168.1.1:9999/EZChat");

            IEZChat proxy = connection.CreateProxy<IEZChat>();

 

            return proxy;

        }

    }

On my server project when form_load this code run.

EZChatServiceRunner.Run();

 

On my client project I wrote this code.

public partial class Form1 : Form

    {

        IEZChat proxy;      

        public Form1()

        {

            InitializeComponent();

            proxy = EZChatClientProxy.CreateProxy();

            proxy.NameRegistered += new Action<string>(proxy_NameRegistered);

        }

 

 

 

 

        private void btnRegister_Click(object sender, EventArgs e)

        {

            proxy.RegisterName(txtName.Text);

 

        }

 

        public void proxy_NameRegistered(string name)

        {

            if (InvokeRequired)

            {

                Invoke(new Action<string>(proxy_NameRegistered), name);

                return;

            }

            MessageBox.Show(name);

        }      

 

    }

 

When I run two clients on my computer (both the same and different computers) and click register button, the message box show only on the last run client two times. I mean that event fire two times on the same client.

 

 

Coordinator
Jan 23, 2013 at 11:10 AM
Edited Jan 23, 2013 at 5:41 PM
specialnas wrote:

I use Zyan 2.4. I already checked the MiniChat example. Everything looks the same.

I have 3 projects. They are server, client, and the library. In library I have one interface. Here is my interface source code.

Hi specialnas!

Thank you for the report. I was finally able to reproduce this mysterious heisenbug :)

Please download the latest source code and build Zyan yourself. We'll include the bugfix in the upcoming release.

Also, I'd like to point out a few things:

  • Your server isn't stopped properly. Add EZChatServiceRunner.Stop method and call host.Dispose() to shut your server down.
  • Establishing connection is far heavier operation than creating a proxy. Create ZyanConnection once and reuse this instance to create all proxies.
  • It's not easy to tell which application shows you the MessageBox you're looking at. All of them look the same and are shown at the center of the screen. Add a title to be sure that MessageBox is shown by particular client :)
Jan 24, 2013 at 12:56 AM

Thanks for useful reply.