以下是我的SignalR Hub類代碼。如何將消息發送給SignalR中的唯一呼叫者客戶端?
public class ChatHub : Hub
{
public void Send(string name, string message)
{
// Call the addNewMessageToPage method to update clients.
Clients.All.addNewMessageToPage(name, message);
}
public async void webAPIRequest()
{
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync("https://jsonplaceholder.typicode.com/posts");
//Clients.All.addWebAPIResponseToPage(response);
Clients.Caller.addWebAPIResponseToPage(response);
await Task.Delay(1000);
response = await client.GetAsync("http://www.google.com");
Clients.Caller.addWebAPIResponseToPage(response);
//Clients.All.addWebAPIResponseToPage(response);
await Task.Delay(1000);
response = await client.GetAsync("https://jsonplaceholder.typicode.com/posts?userId=1");
//Clients.All.addWebAPIResponseToPage(response);
Clients.Caller.addWebAPIResponseToPage(response);
}
}
按我理解,
Clients.Caller.addWebAPIResponseToPage(response);
發送消息僅向呼叫者客戶機,而
Clients.All.addWebAPIResponseToPage(響應);
將消息發送給所有客戶端。
是我的理解是否正確?
如果否,那麼需要調用哪種方法才能將消息發送給調用方客戶端。