SignalR - Send message OnConnected

后端 未结 4 1655
半阙折子戏
半阙折子戏 2021-02-14 02:15

I\'ve been experimenting with SignalR today and It\'s really neat. Basically what I wanted to achieve is the following:

As soon as a device connects it should send a mes

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-14 03:10

    Thanks for all the help (upvoted you guys). Actually found the problem.. it was inside my client. I first subscribed to the 'hello' function and after that I started the HubConnection. As soon as I changed this order everything worked fine.

    It worked with the following client code:

        private async Task ConnectToSignalR()
        {
            var hubConnection = new HubConnection("url");
            hubConnection.Headers["x-zumo-application"] = "clientapikey";
    
            IHubProxy proxy = hubConnection.CreateHubProxy("ChatHub");
    
            proxy.On("hello", async (msg) =>
            {
                Console.WriteLine(msg);
            });
    
            await hubConnection.Start();
        }
    

提交回复
热议问题