Search code examples
javawebsocketsignalrsignalr-hubjava-websocket

How to connect a java client to SignalR Hub using only websockets?


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 ?


Solution

  • 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.