Luuk Wuijster
Luuk Wuijster

Reputation: 6878

.NET Core 2.1 / Angular - SignalR takes exactly 2 minutes to connect to hub

I have an Ionic app and I want it to connect to my socket. This worked in the SignalR preview just fine, and it essensialy still does, but it takes 2 minutes to connect for some reason...

enter image description here

I also get some errors when it connects:

enter image description here

This is my javascript code:

ngOnInit() {

    const connection = new signalR.HubConnectionBuilder()
          .withUrl("http://192.168.178.11:8040/socket?sessionId=3dc1dc11")
          .build();

    connection.on("ReceiveMessage", message => {
      console.log(message);

      this.zone.run(() => {
        if(this.locked == true) {
          this.locked = false
        } else {
          this.locked = true;
        }
      });

      console.log(this.locked);
    });

    connection.start().catch(err => console.error);

}

This is my Hub:

public class DeviceHub : Hub
{
        public override Task OnConnectedAsync()
        {
            var sessionId = Context.GetHttpContext().Request.Query["sessionId"];

            return Groups.AddToGroupAsync(Context.ConnectionId, sessionId);
        }
}

And this is my configuration in Startup.cs:

app.UseSignalR(routes =>
{
    routes.MapHub<DeviceHub>("/socket");
});

Now my question is: How do I solve this?

EDIT 1:

The delay is before the OnConnectedAsync() method is invoked.

EDIT 2:

One more thing I think I should add is that it directly does a request to my API:

ws://192.168.178.11:8040/socket?sessionId=3dc1dc11&id=Pt-JDlSPq2_WEIl-8cdPZA

And that's the request that takes exactly two minutes to finish.

EDIT 3:

One more thing I would like to point out is that I am running a proxy. I cannot connect directy from my phone to the API, so I use a proxy for it. I have no idea if this has anything to do with it, but I just wanted to point it out just in case.

Upvotes: 3

Views: 1208

Answers (1)

Luuk Wuijster
Luuk Wuijster

Reputation: 6878

Well...

Shame on me.

The proxy caused the problem.

I have added bindings for my own IP in Visual Studio and it works now.

To do this open \APPLICATION_FOLDER\.vs\config\applicationhost.config.

Then look for <bindings> and add your own.

Example:

<bindings>
  <binding protocol="http" bindingInformation="*:63251:localhost" />
  <binding protocol="https" bindingInformation="*:44333:localhost" />
  <binding protocol="http" bindingInformation="*:63251:192.168.178.11" />
  <binding protocol="https" bindingInformation="*:44333:192.168.178.11" />
</bindings>

Save it, and you're done.

Note:

From now on you have to launch Visual Studio as administrator otherwise your application won't launch.

Upvotes: 4

Related Questions