I'm trying to send a request and get a response from a socket.
The server only seems to send the response once it gets an EOF. The only way I can seem to get an EOF is to close my output stream. However, when I close my output stream before reading from the input stream I get a "java.net.SocketException: Socket closed" exception.
Is there a way to send an EOF signal in the output stream? Am I doing something wrong?
Socket sock = new Socket(this.getHost(), this.getPort());
DataOutputStream os = new DataOutputStream(sock.getOutputStream());
DataInputStream is = new DataInputStream(sock.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String responseString = new String();
if (sock != null && os != null && is != null) {
os.writeBytes(request);
String responseLine;
while ((responseLine = reader.readLine()) != null) {
responseString += responseLine;
}
} //endif
os.close();
is.close();
sock.close();