 |
Return to article
private String readSocket() throws IOException {
//first line contains the message length
String line = in.readLine();
int headerMessageLength = Integer.parseInt(line);
//read lines from socket until the entire message length has been read
StringBuffer sb = new StringBuffer();
int incrementalMessageLength = 0;
line = in.readLine();
incrementalMessageLength += line.length() + 1;
sb.append(line);
while (incrementalMessageLength < headerMessageLength) {
line = in.readLine();
incrementalMessageLength += line.length() + 1; //add 1 for new line char
sb.append(line);
}
return sb.toString();
}
|
Return to article
|  |
|