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

1

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 ?

Curtsy answered 11/10, 2017 at 6:38 Comment(0)
C
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.

Cove answered 12/10, 2017 at 16:37 Comment(5)
Your sample repo doesn't seem to have an example of connecting to SignalR using websockets - perhaps you've changed this since?Murielmurielle
There is a social weather sample that uses just webSockets: github.com/aspnet/SignalR/blob/dev/samples/SocialWeather/…. It is actually more than that - you can read the entire story here: blog.3d-logic.com/2017/01/15/…Cove
The URL is dead, and the server at github.com/aspnet/SignalR/tree/master/samples/SocialWeather doesn't use SignalR at all. (And the repo is archived and read-only.)Lucy
Folow-up: the WebSocket->SignalR example is at github.com/aspnet/SignalR-samples/tree/pawelka/ticker-ws/… .Lucy
@Cove And there is no possibility to check when a user lost internet connection by timeout. Again. Right?Xanthine

© 2022 - 2024 — McMap. All rights reserved.