0

I have javascript client code:

<script>
$(function () {

    var chat = $.connection.notificationHub;

    chat.client.newMessage = function (message) {
        alert(message);
        // Add the message to the page.
        $('#messages').append('<li><strong>' +  message + '</strong>: </li>');
    };
    $.connection.hub.start().done();
});
</script>

My hub class in an dll name -- signalcomponent

public class NotificationHub : Hub
{
    public async Task SendAll(string message)
    {
        await Clients.All.newMessage(message);
    }
}

my signalrcomponent is now used in another website(backend) from where i want to send message to another website, but using the same hub.

In backend website, i use signalrcomponent dll and samehub

now i try to call the "newMessage" method of other website/client

using following code:

public class NotificationBroadcaster
{
    private IHubContext _hubContext;

    public NotificationBroadcaster()
    {
        _hubContext = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
    }


    public async Task SendAll(string message)
    {
        await _hubContext.Clients.All.newMessage(message);
    }


}

But this is not working

help please

Lars Höppner
  • 18,252
  • 2
  • 45
  • 73
Rusty
  • 1,303
  • 2
  • 14
  • 28
  • I would try the singleton design pattern – Thiago Custodio Dec 26 '13 at 12:09
  • So shd i create NOtificationHub class as singleton ? – Rusty Dec 26 '13 at 13:12
  • Yes, but thinking again, I would try one approach using messaging. I would create a service to dequeue messages and broadcast to clients of the hub. It will take a few more time, but I'll believe it will work. Maybe it won't fix your need because this time to enqueue / dequeue messages will degrade the real time experience. – Thiago Custodio Dec 26 '13 at 13:25
  • i tried with singleton design pattern , but it didnot work – Rusty Dec 27 '13 at 08:20

0 Answers0