My Question: Is there a way to speed up the initial connect to the hub?
Details:
I am using SignalR at a selfhosted Webservice @Win 8.1. The Hub application got local clients and remote clients.
I granded SignalR access via DNS, localhost and 127.0.0.1 by:
'netsh http add urlacl url=http://<Replace>:<Port>/ user=Everyone'
Usually all clients even the local ones are using DNS. And it works.
My problem is one sporned child process (using c# Microsoft.AspNet.SignalR.Client.HubConnection). It usually connects withing 400ms. Thats ok. But sometimes it takes seconds.
I have tried to switch at this client to 127.0.0.1 and localhost but without any change.
Afterwards the initial connect, SignalR is pritty fast.
If there is no easy way I have to switch back to plain UDP.
SignalR Config at Hub:
using System;
using System.Web.Http;
using Microsoft.Owin;
using Microsoft.Owin.Cors;
using Microsoft.Owin.FileSystems;
using Microsoft.Owin.StaticFiles;
using Owin;
[assembly: OwinStartup(typeof(SignalRStartUp))]
namespace Onsite
{
public class SignalRStartUp
{
// Any connection or hub wire up and configuration should go here
public void Configuration(IAppBuilder pApp)
{
try
{
pApp.UseCors(CorsOptions.AllowAll);
pApp.MapSignalR();
pApp.UseFileServer(true);
var lOptions = new StaticFileOptions
{
ContentTypeProvider = new CustomContentTypeProvider(),
FileSystem = new PhysicalFileSystem(Constants.Root)
};
pApp.UseStaticFiles(lOptions);
// Configure Web API for self-host.
var lConfig = new HttpConfiguration();
lConfig.Routes.MapHttpRoute("RemoteApi", "api/{controller}/{action}");
lConfig.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });
pApp.UseWebApi(lConfig);
}
catch (Exception lEx)
{
Logger.Error(lEx);
}
}
}
}
Startup at the Client:
public static string GetConnectionString(string pHost = null)
{
var lHost = pHost ?? GetMainClientDns();
return string.Format("http://{0}{1}", lHost, SignalRPort);
}
private void StartSignalR()
{
try
{
var lConnectionString = GetConnectionString("127.0.0.1");
var lStopWatch = new Stopwatch();
lStopWatch.Restart();
IsConnectingHost = true;
_connection = new HubConnection(lConnectionString, string.Format("AccessKey={0}&Role={0}", Constants.AccessKeyPlugIn));
_connection.Reconnected += SetConnected;
_connection.Reconnecting += SetDisConnected;
MTalkHub = _connection.CreateHubProxy("OnsiteHub");
MTalkHub.On("RequestSetNext", RequestSetNext);
MTalkHub.On("RequestSetPrevious", RequestSetPrevious);
MTalkHub.On("RequestEcho", RequestEcho);
_connection.TransportConnectTimeout = _transportConnectTimeout;
var lTask = _connection.Start();
lTask.Wait();
lStopWatch.Stop();
SetConnected();
}
catch (TargetInvocationException lEx)
{
IsDisconnected = true;
Task.Run(() => TryToConnect());
Logger.Fatal(string.Format("Server failed to start. Already running on: '{0}'", lConnectionString), lEx);
}
catch (Exception lEx)
{
IsDisconnected = true;
Task.Run(() => TryToConnect());
Logger.Fatal(string.Format("Connecting to: '{0}' failed!", lConnectionString.ToStringNs()));
}
finally
{
IsConnectingHost = false;
}
}
After a bugfix for another issue I the long initial connect was also gone.
What I have found: There was a race condition and rarely a lock with FileAccess via network share blocked the Hub by updating the local cached thumbnails.
Thx anyway!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments