我正在寫與信號r服務器測試應用程序和Web客戶端,我想知道是否有一種方法來確定,或使服務器知道哪些運輸方式的客戶端正在與服務器建立。如何確定哪種運輸方式信號R使用
關於在客戶端和服務器之間具有持續雙向連接的websockets或者在服務器響應並且關閉連接之前不斷輪詢服務器的長輪詢,我將不得不意識到任何缺點關於運輸方法不被特別是如果有將要被許多製造了一個又一個長期運行的請求持久雙向連接外網的插座?
我注意到,使得從客戶端的多個請求將由集線器來處理並在完成時返回,例如我發送請求到等待10秒那麼另一個請求等待1秒。集線器將到1秒的等待請求第一然後10秒延遲響應,我很好奇,是否存在每創建請求經由同一個持久雙工連接連接到客戶端的螺紋。
這裏是我的示例代碼。
class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
}
}
public class RunningHub : Hub
{
public void SendLongRunning(string name, string waitFor)
{
Clients.All.addMessage(name, "just requested a long running request I'll get back to you when im done");
LongRunning(waitFor);
Clients.All.addMessage(name, "I'm done with the long running request. which took " + waitFor + " ms");
}
private void LongRunning(string waitFor)
{
int waitTime = int.Parse(waitFor);
Thread.Sleep(waitTime);
}
}
JQuery Sample。
$(function() {
//Set the hubs URL for the connection
$.connection.hub.url = "http://localhost:9090/signalr";
// Declare a proxy to reference the hub.
var signalHub = $.connection.runningHub;
$('#url').append('<strong> Working With Port: ' + $.connection.hub.url + '</strong>');
// Create a function that the hub can call to broadcast messages.
signalHub.client.addMessage = function (name, message) {
//handles the response the message here
};
// Start the connection.
$.connection.hub.start().done(function() {
$('#sendlongrequest').click(function() {
signalHub.server.sendLongRunning($('#displayname').val(), $('#waitTime').val());
});
});
});