10

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

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

1 回答 1

3

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

.....
connection.start({ callback: function () {
var username = getCookie("username");
connection.send(window.JSON.stringify({ type: 0, value: username }));
}
});
......
于 2011-12-29T23:05:35.073 回答