加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – SignalR OnConnected – 发送连接的客户端消息

发布时间:2020-12-15 06:46:16 所属栏目:百科 来源:网络整理
导读:很简单的问题为什么刚刚连接的客户端没有收到任何消息,但是所有其他客户端都会收到广播?发送连接消息的客户端的正确方法是什么? protected override void OnConnected(HttpContextBase context,string clientId){ GameAction message = new GameAction();
很简单的问题为什么刚刚连接的客户端没有收到任何消息,但是所有其他客户端都会收到广播?发送连接消息的客户端的正确方法是什么?
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 }));
}
});
......

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读