So recently I got into web development (.NET Core 3.0 Razor Pages) and decided to get into SignalR for my RPC.
Only problem is, that I've only been able to connect to the hub from JavaScript, when I try to connect to the hub using C# and the .NET Core it throws me 3 exception, a SocketException an IOException and a HttpRequestException (full stack traces below)

This is my code:

private HubConnection _connection;

public async Task OnGet()
{
    var connection = new HubConnectionBuilder().WithUrl("http://127.0.0.1:44389/Hub/FingerprintHub").Build();
    // The program waits here and 
    // after roughly 2 minutes throws the exceptions
    await _connection.Start();
}

and my Hub looks like this:

public class FingerprintHub : Hub
{
    public async Task ScanFingerprint(string fingerprint)
    {
        await Clients.All.SendAsync("FoundFingerprint", fingerprint);
    }
}

I configured my services like so:

app.UseWebSockets();
app.UseSignalR(routes => { routes.MapHub<FingerprintHub>("/Hub/FingerprintHub"); });

I'm using the Microsoft.AspNetCore.SignalR.Client and Microsoft.AspNetCore.SignalR.Client.Core 3.0.0-preview5 version with the .NET Core Preview 5-011568


SocketException: An existing connection was forcibly closed by the remote host.

System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.

IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..

System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host. --- End of inner exception stack trace --- at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token) at System.Net.Http.HttpConnection.FillAsync() at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean foldedHeadersAllowed) at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)

HttpRequestException: An error occurred while sending the request.

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host.

0 Answers