I need to access a websocket server that runs with SignalR Hub, from my Java desktop application.
When I tried to access the server directly with websocket, the HTTP handshaking fails (I get HTTP 200 instead of 101).
Can anyone help ?
SignalR. ASP.NET Core SignalR is a library that simplifies adding real-time web functionality to apps. It uses WebSockets whenever possible. For most applications, we recommend SignalR over raw WebSockets.
Messages sent by the server to the client can include plain text messages, binary data, or images. Whenever data is sent, the onmessage function is fired. This event acts as a client's ear to the server. Whenever the server sends data, the onmessage event gets fired.
WebSocket is a two-way communication protocol that lets clients send and receive messages over a single connection to a server endpoint. Download a PDF of this article. WebSocket is a two-way communication protocol that lets clients send and receive messages over a single connection to a server endpoint.
SignalR provides two built-in hub protocols: a text protocol based on JSON and a binary protocol based on MessagePack. MessagePack generally creates smaller messages compared to JSON. Older browsers must support XHR level 2 to provide MessagePack protocol support.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With