【问题标题】:SignalR OnConnected - Sending Connected Client a MessageSignalR OnConnected - 向连接的客户端发送消息
【发布时间】:2011-12-30 07:41:55
【问题描述】:

很简单的问题。为什么刚刚连接的客户端没有收到任何消息,而其他所有客户端都收到了广播?发送连接消息的客户端的正确方法是什么?

protected override void OnConnected(HttpContextBase context, string clientId)
{      
    GameAction message = new GameAction();
    message.text = "Player connected";
    Connection.Broadcast(serializer.Serialize(message));

    GameAction gamestate = new GameAction(); 
    gamestate.text = "Some client specific info";     
    Send(clientId, serializer.Serialize(gamestate));      
}

【问题讨论】:

    标签: c# asp.net signalr


    【解决方案1】:

    我认为您应该在您的 javascript 中的 connection.start() 函数中放置一个回调函数并重新发送您的命令。 JSON中单独的广播消息和回显消息类型可以帮助您在加入后检测连接状态... 波纹管对我有用..

    .....
    connection.start({ callback: function () {
    var username = getCookie("username");
    connection.send(window.JSON.stringify({ type: 0, value: username }));
    }
    });
    ......
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-19
      • 1970-01-01
      • 2011-11-28
      • 1970-01-01
      • 1970-01-01
      • 2015-01-12
      相关资源
      最近更新 更多