My client first creates a url object with the url of the server (containing the servlet) and sends data to the servlet using the following code:
URL url = new URL("http://localhost:8080/hello");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
ObjectOutputStream out=new ObjectOutputStream(connection.getOutputStream());
out.writeObject(stringToReverse);
After receiving the required data from the server, the client again needs to send a data to the servlet. Should I close the above ObjectOutptStream and create a new one within the same connection to send the data? How should it be done?
Another question that I have is that each time I write data into the outputstream of the client, should I create a separate ObjectInputStream in the servlet?