I have JavaApplication that when it starts it opens socket and listen to connection (like server).
I also have WebApplication that should take some data from the JavaApplication and display it in WebBrowser. To implement this I thought to:
- using Servlet I can connect to that JavaApplication using socket and get the data
- create WebService: WebApplication will send request to WebService and WebService will open socket and connect to the JavaApplication.
- your approach
All this located in the same server.
Does second approach looks way over because eventually I open socket so I can do it from Servlet and not talking to WebService in the middle?
There is no answer to this question – there is simply no information to base this decision on.
Writing a web service is a lot of work, so approach #1 would avoid “useless” work. On the other hand, it would make the Java service available to other uses because other applications (or even other web services) could use the web service to talk to it.
So if this work will be useful for others as well, implement it as a web service. That would also allow you to deploy the web service on its own, so access to the java app wouldn’t depend on whether your web app is running or not.