简体   繁体   中英

Spring websocket with sockjs and stomp client side design

I am integrating spring web-sockets into a web application. And I want to use this for two calls that are taking really long time in ajax. As per my understanding I see there are different design choices about how do I go about with this. I am thinking about the following, can you let me know what would be the best option and if so why

1) Open a socket connection once user logs into the application through SockJS and use this connection to send messages and to subscribe for the two calls that I want to make. One of the question I had with this design is that if the user just closes the browser will the socket connection stay open?

2) Open a socket connection for each call and close it after recieving the message but here it takes up lots of resources to establish a connection each time.

I am pretty new to spring-websocket, SockJS and STOMP stuff so let me know my understanding is wrong anywhere?

Thanks in advance

  1. When user closes browser, then Web Socket will be disconnected. You can handle it at server side. I mean, you can notify for other users or something again.

  2. You need open web socket connection when after browser loading, one time. You can save this connection while browser is open. Don`t disconnect connection after call. Just stop sending data packet.

I think this design will help you.

Some useful links:

Detecting WebSocket Connects and Disconnects in Spring 4

Official Issue about disconnecting

UPDATE (19-March 2016):

There are concurrency will help you. It means that every new connection will be handled by new threads . So, they can work as parallel . Of course, thread's count must be limited by ThreadPool 's. So, this kind of issues already solved and implemented in Spring Web Socket .

If you are interested with fundamental theories, then you can read this answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM