7

I need to access a websocket server that runs with SignalR Hub, from my Java desktop application.

  • There is a library that does exactly that, but it's dead. There are lots of issues and pull requests and it hasn't been updated since 2015.
  • I also found another library but, as far as I can tell, it's only for Android projects.
  • I found a SO question that says it's possible to talk directly to the SignalR server (standard websocket calls) with some workarounds, but the given link is dead.

When I tried to access the server directly with websocket, the HTTP handshaking fails (I get HTTP 200 instead of 101).

Can anyone help ?

1 Answers1

7

You will not be able to connect to SignalR 2.x with just bare webSocket. The reason for that is that starting the connection requires a few HTTP requests which have to be sent with in a specific order and contain specific content. I described the SignalR protocol in a blog post. After reading this post you will understand why dedicated client for SignalR 2.x existed.

Having said that - the new version of SignalR for ASP.NET Core no longer has this protocol and requirements and it is possible to connect to the server with just bare websockets. I created a demo a while ago showing how to do this - you can find details here. I also started working on an example for the hubs layer but need to finish it.

Pawel
  • 31,342
  • 4
  • 73
  • 104
  • 1
    Your sample repo doesn't seem to have an example of connecting to SignalR using websockets - perhaps you've changed this since? – Dave New Mar 16 '18 at 09:17
  • 1
    There is a social weather sample that uses just webSockets: https://github.com/aspnet/SignalR/blob/dev/samples/SocialWeather/wwwroot/index.html#L70-L100. It is actually more than that - you can read the entire story here: https://blog.3d-logic.com/2017/01/15/signalr-core-part-23-asp-net-sockets/ – Pawel Mar 16 '18 at 16:08
  • The URL is dead, and the server at https://github.com/aspnet/SignalR/tree/master/samples/SocialWeather doesn't use SignalR at all. (And the repo is archived and read-only.) – Mike Rosoft Oct 13 '20 at 11:41
  • Folow-up: the WebSocket->SignalR example is at https://github.com/aspnet/SignalR-samples/tree/pawelka/ticker-ws/StockTickR/StockTickRApp . – Mike Rosoft Oct 13 '20 at 11:49
  • @Pawel And there is no possibility to check when a user lost internet connection by timeout. Again. Right? – daniil_ May 08 '23 at 19:07