簡體   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