SpringBoot app terminated immediately after establishing connection via Websocket

30 Views Asked by At

I've created a pet project for evaluating how to send a message from server to clients via Websockets. You can find the code here: https://github.com/sergmain/spring-boot-websockets

If I run server and then client all work fine.
If I run server, then client, and then restart server all work fine too.
But if I run client in first place and then server, client exits just after establishing connection with server:

2024-02-07T17:52:42.298-08:00 TRACE 628 --- [lient-AsyncIO-8] s.w.s.h.LoggingWebSocketHandlerDecorator : Handling TextMessage payload=[CONNECTED
..], byteCount=39, last=true] in StandardWebSocketSession[id=005c6907-e62b-7053-2b87-c8aa7dba87c1, uri=null]
2024-02-07T17:52:42.300-08:00 TRACE 628 --- [lient-AsyncIO-8] o.s.messaging.simp.stomp.StompDecoder    : Decoded CONNECTED {version=[1.2], heart-beat=[0,0]} session=null
2024-02-07T17:52:42.301-08:00 TRACE 628 --- [lient-AsyncIO-8] o.s.m.simp.stomp.DefaultStompSession     : Received CONNECTED {version=[1.2], heart-beat=[0,0]} session=d7c8c910-73e7-9438-d71b-19b2f5821354
afterConnected()
2024-02-07T17:52:42.303-08:00 TRACE 628 --- [      Thread-34] o.s.m.simp.stomp.DefaultStompSession     : Sending SUBSCRIBE {destination=[/topic/new-task], id=[0]} session=d7c8c910-73e7-9438-d71b-19b2f5821354
2024-02-07T17:52:42.303-08:00 TRACE 628 --- [      Thread-34] o.s.messaging.simp.stomp.StompEncoder    : Encoding STOMP SUBSCRIBE, headers={destination=[/topic/new-task], id=[0]}
2024-02-07T17:52:42.303-08:00 TRACE 628 --- [      Thread-34] o.s.w.s.adapter.NativeWebSocketSession   : Sending TextMessage payload=[SUBSCRIBE
..], byteCount=45, last=true], StandardWebSocketSession[id=005c6907-e62b-7053-2b87-c8aa7dba87c1, uri=null]

Process finished with exit code 1

Is this a bug or I'm doing something in wrong way?

For sending message from server to client you can use the following url http://localhost:8080/task?t=42

UPD:
original branch with question now is so-question
main branch contains working code. How is this code correct from Spring's architecture point of view - idk.

0

There are 0 best solutions below