Issue
In my java project I have a Server class(using ServerSocket) and a client class(using Socket). In addition I also implemented a servlet application which is running on Tomacat 8 The servlet acts as extra input source(in other words its another client).
I'd like to send the data which is filled up from the servlet web page to the Server Socket. I already got the data from the web form using request.getParameterMap()
command
I use json in order to wrap the data before sending it between Client and Server. i'd like to do the same with the servlet but I cant find the right way to do that.
Thanks!
Solution
As you already have client class so you just need to use it effectively. Make your client code generic with a simple interface so that it can be called from anywhere. Servlets are java classes, they can call any other class to do some additional work. In your case, you can use data received in Servlet and pass it on to the client to send it to your server.
Make sure that client code should not block the servlet for too long to decrease its responsiveness. If it does then you can do the client logic in a separate thread so that your servlet can respond quickly.
Answered By - Juned Ahsan