简体   繁体   English

是否可以仅将信号器用于从服务器到客户端的数据接收?

[英]Is it possible to use the signalr only for receiving data from server to Client?

I am Developing a Sample Application in SignalR. 我正在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:- 这是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. 我需要在类之外使用HubClass。因此,我在解决方案中使用了该Hub类的对象。

Sample:- 样品:-

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

This is my Owin StartupClass:- 这是我的Owin StartupClass:

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

MyClientSide Code:- MyClientSide代码:-

$(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? 请确保我做对了还是错了?

  1. To get Hub instance outside pipeline: How to use SignalR hub instance outside of the hubpipleline 要使Hub实例不在管道中: 如何在hubpipleline之外使用SignalR Hub实例
  2. Don't forget start client side connection: $.connection.hub.start() 不要忘记启动客户端连接: $.connection.hub.start()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM