0

I am Developing a Sample Application in SignalR. My Requirement is i need to receive datas from server to client.But i didn't any pass values from client to server.

Is it possible to use the signalr only for receiving data from server to Client and i did correct?

This is myHubClass:-

public  class NameHub : Hub
{
 public void send(string Item,string Info)
 {
  //var name = GlobalHost.ConnectionManager.GetHubContext<NameHub>();
  Clients.All.broadcastMessage(Item,Info);
}
}

I need to use the HubClass outside the class.so i created a object for that hub class ,used in my solution.

Sample:-

using (NameHub n = new NameHub())
{
 n.Clients.All.broadcastMessage(datePicker, IsLoad);
}

This is my Owin StartupClass:-

public class Startup
{
  public void Configuration(IAppBuilder app)
  {
    app.MapSignalR();
  }
}

MyClientSide Code:-

$(function () {
   var data = $.connection.NameHub;
   data.client.broadcastMessage = function (Item,Info) {
   $('div.container').append('<p><strong>'+Item+"=" 
           + Info + '</strong></p>');
};

Could Anyone Provide me an solution to solve this?

Please ensure i did correctly or wrong?

Thiru Arasu
  • 293
  • 1
  • 5
  • 23

1 Answers1

1
  1. To get Hub instance outside pipeline: How to use SignalR hub instance outside of the hubpipleline
  2. Don't forget start client side connection: $.connection.hub.start()
Community
  • 1
  • 1
Igor Lizunov
  • 539
  • 5
  • 12