Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to dynamically generate key for a channel and publish? #16

Open
cashberry opened this issue Oct 15, 2019 · 0 comments
Open

How to dynamically generate key for a channel and publish? #16

cashberry opened this issue Oct 15, 2019 · 0 comments

Comments

@cashberry
Copy link

cashberry commented Oct 15, 2019

Hi,
We wrote the following code to do dynamic key generation for a channel and publish message to this channel using key generated. But publish is not working...

Code looks as follows,

using Emitter;
using System;
using System.Linq;
using System.Text;

namespace EmitterSample
{
    class Program
    {
        private static readonly string _secretKey = "LhlUB9xti-UGMuvGw83Rv0SEdYD3r2dy";
        private static Connection _connection;
        static void Main(string[] args)
        {
            _connection = new Connection("127.0.0.1", 8080, "");
            _connection.Error += _connection_Error;
            _connection.Disconnected += _connection_Disconnected;
            _connection.Connect();
            _connection.GenerateKey(_secretKey, "chat/", Emitter.Messages.EmitterKeyType.ReadWrite, 1200, response =>
             {
                 CheckMillionMessage(response.Key, response.Channel);
             });
            Console.WriteLine(_connection.IsConnected);

            Console.WriteLine("Press any key to continue....");
            Console.ReadKey();
            _connection.Disconnect();
        }

        private static void _connection_Disconnected(object sender, EventArgs e)
        {
            Console.WriteLine("Disconnected");
        }

        private static void _connection_Error(object sender, Exception e)
        {
            Console.WriteLine(e);
        }

        private static void CheckMillionMessage(string key, string chName)
        {
            int received = 0;
            _connection.On(key, chName, (channel, msg) =>
            {
                received++;
                Console.WriteLine($"{Encoding.UTF8.GetString(msg)} - {received}");
            });


            for (int i = 0; i < 10; i++)
            {
                _connection.Publish(key, chName, "Hello from client", 1200);
            }
        }
    }
}

Please let us know what will be the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant