Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JSP Interest »

Re: [OT] Multiple text lines over socket

Jonathan Mangin

2004-06-20

Replies:

----- Original Message -----
From: "Jonathan Mangin" <jon.mangin@(protected)>
To: <JSP-INTEREST@(protected)>
Sent: Saturday, June 19, 2004 11:16 AM
Subject: [OT] Multiple text lines over socket


Sorry about OT...

Can someone point me to a technique for reading multiple lines terminated
with newlines (paragraphs?) from a socket in a single read?

Thanks,
Jon




To answer my own question:

StringBuffer buffer = new StringBuffer();
while ((text = socketIn.readLine()) != null) {
 if (!text.equals("bye")) {
   buffer.append(text + "\n");
   continue; // Doh!
 }
 System.out.println(buffer);
 ...
 buffer = new StringBuffer();
 ...
}

===========================================================================
To unsubscribe: mailto listserv@(protected)".
For digest: mailto listserv@(protected)".

Some relevant archives, FAQs and Forums on JSPs can be found at:

http://java.sun.com/products/jsp
http://archives.java.sun.com/jsp-interest.html
http://forums.java.sun.com
http://www.jspinsider.com
©2008 junlu.com - Jax Systems, LLC, U.S.A.