question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SignalR Java client unable to open WebSocket

See original GitHub issue

Describe the bug

I’m unable to connect to a ASP.NET Core SignalR hub from the Java client. I’ll specify all versions of things below to hopefully make this more understandable.

Every time I start the HubConnection object, I get the following error:

Aug 08, 2019 4:21:12 PM com.microsoft.signalr.OkHttpWebSocketWrapper$SignalRWebSocketListener onFailure
SEVERE: WebSocket closed from an error: Expected HTTP 101 response but was '200 OK'.
Aug 08, 2019 4:21:12 PM com.microsoft.signalr.WebSocketTransport onClose
INFO: WebSocket connection stopping with code null and reason 'Expected HTTP 101 response but was '200 OK''.
Aug 08, 2019 4:21:12 PM com.microsoft.signalr.HubConnection stopConnection
SEVERE: HubConnection disconnected with an error Expected HTTP 101 response but was '200 OK'.
Aug 08, 2019 4:21:12 PM com.microsoft.signalr.HubConnection stopConnection
INFO: HubConnection stopped.

I’ve confirmed that WebSockets are enabled on the hub (as I can see it as an option returned during the negotiation phase), eg:

{
    "connectionId": "...",
    "availableTransports": [
        {
            "transport": "WebSockets",
            "transferFormats": [
                "Text",
                "Binary"
            ]
        },
        {
            "transport": "ServerSentEvents",
            "transferFormats": [
                "Text"
            ]
        },
        {
            "transport": "LongPolling",
            "transferFormats": [
                "Text",
                "Binary"
            ]
        }
    ]
}

I’ve also tried setting shouldSkipNegotiate() on the Java client, and making sure that only the WebSocket transport was configured for the hub, but that yielded the same result.


To Reproduce

Versions

  • Microsoft.AspNetCore.App 2.2.0
  • Microsoft.AspNetCore.SignalR 1.1.0
  • Java 1.8.0_77
  • com.microsoft.signalr 3.0.0-preview7.19365.7
  1. Build a HubConnection object, with an access token provider. Eg:
hubConnection = HubConnectionBuilder.create("http://localhost:52929/rtc")
    	.withAccessTokenProvider(Single.defer(() -> {
    		String token = getToken("username", "password"); // token fetch logic
    		return Single.just(token);
    	}))
    	.build();
  1. Start the HubConnection
  2. Receive the error above

Expected behavior

I expect the client to connect to the hub, and receive messages.

Additional context

I originally picked this issue up while writing a module for a 3rd party product, with an embedded SignalR client. I’ve replicated this in a standalone Java program though, so I’m rolling with the standalone program until I can confirm it works without any interference from the 3rd party product.

Include the output of dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   2.2.401
 Commit:    729b316c13

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.401\

Host (useful for support):
  Version: 2.2.6
  Commit:  7dac9b1b51

.NET Core SDKs installed:
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.401 [C:\Program Files\dotnet\sdk]
  2.1.403 [C:\Program Files\dotnet\sdk]
  2.1.502 [C:\Program Files\dotnet\sdk]
  2.1.700 [C:\Program Files\dotnet\sdk]
  2.2.101 [C:\Program Files\dotnet\sdk]
  2.2.103 [C:\Program Files\dotnet\sdk]
  2.2.300 [C:\Program Files\dotnet\sdk]
  2.2.401 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.3-servicing-26724-03 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Stoolbendcommented, Aug 8, 2019

Sure. So try running in Kestrel perhaps?

0reactions
Stoolbendcommented, Aug 14, 2019

Ok I’ve got it now. In my web.config file, I had a rule that handled HTML5 routes for the SPA website that it hosts. It had some exclusions in for the /api/* and /health endpoints, but not for the SignalR endpoints. Entirely my fault for this one.😞

<rule name="html5-routes" stopProcessing="true">
  <match url=".*" />
  <!-- Handle all paths except /api/ and pass the route onto the wwwroot/index.html -->
  <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <!-- Add rule to negate file requests e.g. css/html/images-->
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <!-- Add rule to negate directories-->
    <add input="{REQUEST_URI}" pattern="^/api/|^/health" negate="true" />
    <!-- Add rule to negate paths and let them through the MVC-->
    <add input="{HTTP_METHOD}" pattern="GET|HEAD" />
  </conditions>
  <action type="Rewrite" url="wwwroot/index.html" />
</rule>

After I added |^/rtc|^/metadata to the “Add rule to negate directories” section, it started working in IIS Express.

At least that explains why it was working in Kestrel, and not IIS Express (or I imagine IIS if I was to test using that).

Read more comments on GitHub >

github_iconTop Results From Across the Web

SignalR Java client unable to open WebSocket #12973
I'm unable to connect to a ASP.NET Core SignalR hub from the Java client. I'll specify all versions of things below to hopefully...
Read more >
How to connect a java client to SignalR Hub using only ...
1 Answer 1 ... You will not be able to connect to SignalR 2.x with just bare webSocket. The reason for that is...
Read more >
ASP.NET Core SignalR Java client
The Java client enables connecting to an ASP.NET Core SignalR server from Java code, including Android apps. Like the JavaScript client and ...
Read more >
SignalR vs. WebSocket: Key differences and which to use
We compare SignalR and WebSocket, two popular realtime technologies. Discover their advantages and disadvantages, use cases, and key ...
Read more >
External SignalR clients - Scientific Programmer
NET client; Setting up Java client; Setting up a raw WebSocket client ... To do it, open your command line terminal inside the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found