繁体   English   中英

SignalR OnConnected - 向连接的客户端发送消息

[英]SignalR OnConnected - Sending Connected Client a Message

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

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));      
}

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

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

暂无
暂无

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

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