2011-12-14 112 views
10

非常簡單的問題。爲什麼剛剛連接的客戶端沒有收到任何消息,但所有其他客戶端都收到了廣播?發送連接消息的客戶端的正確方式是什麼?SignalR OnConnected - 發送連接的客戶端消息

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

回答

3

我想你應該把一個回調函數在connection.start()函數在JavaScript並重新發送您的命令。分離式的JSON廣播消息和Echo消息可能會幫助您檢測連接的狀態,你加入...... 波紋管爲我工作以後。

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