4

Using SignalR for ASP.NET Core 2.0, Client side (1.0.0-alpha2-final), C# VS2017.

To connect the code is: await hubConnection.StartAsync(); since this is an await for a void how can we test if the client did manage to connect ? In my tests I have a breakpoint on the server side in public override async Task OnConnectedAsync() but that breakpoint is not always hit therefore I know that sometimes the client does not connect. Or perhaps it did connect but OnConnectedAsync() was not triggered?

How can the client knows it succeeded in establishing the connection?

Thanks

Edit: More info. It does fire OnConnectedAsync() when using localhost (debugging in VS); it does not fire OnConnectedAsync() when connecting through ngrok. Maybe this is something to do with proxy/CORS, I am not familiar with.

Edit: It appears that the Client does indeed connect because if I change the URL to a non existing one it gives a 404. So it appears that the problem is that OnConnectedAsync() does not fire when the client connects through ngrok but does fire when connected directly to localhost.

Pawel
  • 31,342
  • 4
  • 73
  • 104
Frank Monroe
  • 1,557
  • 2
  • 13
  • 20

1 Answers1

2

StartAsync is not a void method but returns a Task. If the client does not connect StartAsync throws (returns a faulted task) otherwise the async call will complete without an error (returns a completed task) after the client is successfully connected.

Pawel
  • 31,342
  • 4
  • 73
  • 104
  • You are right. Thanks for pointing this out. To be more clear my problem is rather as I explained in the 2nd Edit of my post: The StartAsync *does* throw when the end point (URL) *does not* exist. When the proper URL is supplied it *does not* throw BUT on the server the `OnConnectedAsync()` *does* fire when I use localhost but *does not* fire when I connect through a proxy such as ngrok. Why? – Frank Monroe Nov 02 '17 at 01:02