我的服务器端代码:
_hub = connection.CreateHubProxy("TestHub");
connection.Start().Wait();
_hub.On("RcvSendToUser", x => Console.WriteLine(x));
我的客户端代码:
message
当客户端收到{{1}}时,客户端是否可能向服务器端响应字符串值?如果可能,如何在两者上修改我的代码?
答案 0 :(得分:0)
One way is to add a new method in your server side hub and call it from the client.
Add this method to the hub in server:
public void AcknowledgeServer(String ack) {
// Do your stuff.
}
And modify the client code a little bit:
_hub.On("RcvSendToUser", x => {
Console.WriteLine(x);
// Now call the server method with the string value.
_hub.Invoke("AcknowledgeServer", "Your string to server")
});