Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Buffer size or other? Please help  RSS feed

Hongqing Lu
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TestServlet runs in Tomcat, it try to get data from socket server then response to client.
It runs well when the data is small. However it will crash when the data is big enough(about 8k). The break point is in the while loop when reading data from BufferedReader in method doSendRequestTCN2.
I have tyied several methods, but all faild.
I have no idea about it.
Is it caused by buffer size or other?
Please help!!!
Sample source code:
public class TestServlet extends HttpServlet {
public void init(ServletConfig servletConfig) throws ServletException {
public void service(HttpServletRequest req,
HttpServletResponse resp) throws ServletException,
IOException {
try {
PrintWriter out = resp.getWriter();
// get response from socket server
String response = Test.doSendRequestTCN2(requestString);
} catch (Exception ex) {
throw new ServletException("Exception in service method: " +
class Test{
public static String doSendRequestTCN2(String input){
StringBuffer fileLines = new StringBuffer();
String response = null;
client = new Socket(host_ip, host_port);

socketWriter = new PrintWriter(client.getOutputStream());
// get stream from socket server
socketReader = new BufferedReader(new InputStreamReader(client.getInputStream()));
String line = null;
int i = 0;
int sizeOfBuffer = 100;
char[] cbuf = new char[sizeOfBuffer];

int chars = 0;
// read from buffered stream
while ( (chars = >= 0) {
fileLines.append(cbuf, 0, chars);
response = fileLines.toString();
catch (Exception e) {
throw new WMSException(e);
return response;
Please help!
Thanks in advance!!!
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!