Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR OnConnected - Sending Connected Client a Message

Very simple question. Why does the client that has just connected not receive any messages, but all other clients get the broadcast? What's the correct way of sending the client that connected 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));      
}
like image 675
Serge Avatar asked Dec 14 '11 20:12

Serge


1 Answers

I think you should put a call back function in a connection.start() function in your javascript and resend your command. Separate type of broadcast message and echo message in JSON may help you detect status of connection after you join in... The bellows work for me..

.....
connection.start({ callback: function () {
var username = getCookie("username");
connection.send(window.JSON.stringify({ type: 0, value: username }));
}
});
......
like image 79
hoanganh17b Avatar answered Oct 12 '22 10:10

hoanganh17b