Xamarin (android) with SignalR Core can't connect to the hub using websocket

0

I am making a simple cross platform game and want to use SignalR (ASP.Net core 3.1). I have installed nuget package - Microsoft.AspNetCore.SignalR.Client. This all worked as expected, but then I realized that the Android (9.0) client is not using the websocket. Then I wrote the following code on the server:

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapHub<GamesControlHub>("/hubs/GamesControlHub", options => {
                options.Transports = Microsoft.AspNetCore.Http.Connections.HttpTransportType.WebSockets;
            });
        });

Also I added the following code to the client class

        connection = new HubConnectionBuilder()
            .WithUrl(baseAddress + HUB_ROUTE, HttpTransportType.WebSockets)
            .Build();

After this, the android client cannot establish a connection to the server side. No error exception is raised, just waiting for the code to execute:

        await connection.StartAsync();

However, the Windows client can establish a connection to the server without any problems with their code. For android I changed the transport and it worked well. I also tried to have the server and phone on the same local network.

This file contains the Startup.cs code and the server and client hub code: Git gist

Using logging I got the following:

08-08 22:56:15.251 D/Mono    ( 5906): Found as 'mono_btls_ssl_ctx_set_max_version'.
[0:] Microsoft.AspNetCore.Http.Connections.Client.HttpConnection: Error: Failed to start connection. Error starting transport 'WebSockets'.

  System.Net.WebSockets.WebSocketException (0x80004005): The WebSocket request or response contained unsupported header(s).
  at               
  System.Net.WebSockets.WebSocketHandle.ParseAndValidateConnectResponseAsync (System.IO.Stream stream, System.Net.WebSockets.ClientWebSocketOptions options, System.String expectedSecWebSocketAccept, System.Threading.CancellationToken cancellationToken) [0x000c2] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs:329 
  at System.Net.WebSockets.WebSocketHandle.ConnectAsyncCore (System.Uri uri, System.Threading.CancellationToken cancellationToken, System.Net.WebSockets.ClientWebSocketOptions options) [0x00383] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs:148 
  at System.Net.WebSockets.ClientWebSocket.ConnectAsyncCore (System.Uri uri, System.Threading.CancellationToken cancellationToken) [0x000d1] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocket.cs:157 
  at Microsoft.AspNetCore.Http.Connections.Client.Internal.WebSocketsTransport.StartAsync (System.Uri url, Microsoft.AspNetCore.Connections.TransferFormat transferFormat, System.Threading.CancellationToken cancellationToken) [0x001f2] in <423f070b588e409c9c3d9e7dcff65f90>:0 
  at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.StartTransport (System.Uri connectUrl, Microsoft.AspNetCore.Http.Connections.HttpTransportType transportType, Microsoft.AspNetCore.Connections.TransferFormat transferFormat, System.Threading.CancellationToken cancellationToken) [0x00097] in <423f070b588e409c9c3d9e7dcff65f90>:0 
 08-08 22:56:15.668 D/Mono    ( 5906): DllImport searching in: 'libmono-btls-shared' ('./libmono-btls-shared.so').

After delving into the topic, I realized that the problem occurs when using the https protocol.

UPDATE 1

Using a valid certificate and local networks allows you to connect to the hub successfully using https. Hence the problem is in my pfSense router with HAProxy.

c#
asp.net-core
xamarin
signalr

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0