I would like to implement a WebSocket server in Spring Web (managed by Spring Boot) that allows a connected client only to receive a data stream, for instance a simple plain-text or a STOMP message. I'm reading the documentation and a guide on the official web site, but in these cases, they consider a bidirectional conversation (also the client could send messages to the server).
For my scenario, represent WebSockets the right way (yes, I'm a newbie in this field)?
If yes, how can I implement a WebSocket as said? Should I define a
@Controller and an handler?
Furthemore, is it possible to allow the communication only for a given client (by setting the route, the IP address, a token, etc.)?
Cheers, V.
"Receive a data stream" is a technical solution for your scenario, but not the scenario itself. So I can't answer that question.
A controller is only needed for incoming requests. In your case the client would subscribe to a topic and the server publishes data. In order to do that you register a broker as described in 20.4.2 Enable STOMP over WebSocket. Then you send data to that broker / topic as described in 20.4.5 Sending Messages. The broker then delivers to the client. That would be a solution using STOMP. With direct Websocket usage you are on your own.
Yes, but that's not part of the websocket support of Spring. You can use Spring Security for that, if you like.
For what it's worth: A websocket connection is always bidirectional, regardless how you handle 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