Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Will my implementation of a Spring Boot app work after being deployed on the Internet?
Say I want to implement a very basic group chat application. I use the H2 database, a user class, a controller, and a text file in the Resources folder that stores the chat texts. All texts would be appended to the text file and a JS function would refresh the page periodically with the file data. Now of course this will directly work only within my network. But if I upload this project to Heroku or something similar, would it still work as intended?
Almost all examples online use WebSocket. I'm unable to understand why because everyone connecting to the my app online will be served by the same controller and append data to the same text file. Or am I completely wrong?
1 answer
Now of course this will directly work only within my network. But if I upload this project to Heroku or something similar, would it still work as intended?
I'll assume that you actually have the project working on your network. The only advice I can really give you here is, "Try it and see if it works." And if it doesn't work, debug.
Almost all examples online use WebSocket. I'm unable to understand why because everyone connecting to the my app online will be served by the same controller and append data to the same text file. Or am I completely wrong?
The reason most examples use WebSocket is because WebSockets are bi-directional. i.e, the server can push data to the client without being asked for it. Obviously, this is ideal for real-time chat applications, where you want the server to send you chat updates as fast as possible.
In your case though, you are using the "repeatedly polling the server for data" method. While theoretically, this would work, it would only update the chat log as fast as the client requests data. Further, depending on how frequently you poll the server, this can be resource intensive on the server because the data is being repeatedly requested even when there are no changes. However, it does have the advantage of not having to maintain an active connection, so if you don't need real-time updates then this is a perfectly viable method.
1 comment thread