Question on ServerSocket Program: !_NEWLINE_!
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Helena_Zhang
Posted On:   Monday, September 23, 2002 10:33 AM

My server accept each client connection in a seperate thread to get request /send response . But my client can not get the response because the socket has been closed. The SocketServer program just like the sample code on Page 159 in the book "Java in a Nutshell". The test client will make a connection to the server first, then call the following receiveMessage method: public String receiveMessage() throws Exception { String msgReceived = null; // get the message try{ BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String l; while ((l = reader.readLine()) != null) { //for(String l = null; (l =    More>>

My server accept each client connection in a seperate thread to get request /send response .
But my client can not get the response because the socket has been closed.

The SocketServer program just like the sample code on Page 159 in the book "Java in a Nutshell".

The test client will make a connection to the server first, then call the following receiveMessage method:

			

public String receiveMessage() throws Exception {

String msgReceived = null;

// get the message
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(in));

String l;

while ((l = reader.readLine()) != null) {
//for(String l = null; (l = reader.readLine()) != null;){
msgReceived = msgReceived + l;
}
System.out.println("msgReceived: "+msgReceived);

reader.close();
} catch(Exception e){
System.out.println("Exception in receiveMessage: "+e.getMessage());
cat.debug("socket.toString(): " + sock.toString());
throw new Exception(e.getMessage());
}
return msgReceived;

} // end of receiveMessage()




But instead of geting the "msgReceived: ......", I got the
"SocketException in receiveMessage: Socket closed"

Any idea or suggestion? Thank you!    <<Less

Re: Question on ServerSocket Program: !_NEWLINE_!

Posted By:   Laxman_Subramanian  
Posted On:   Monday, September 23, 2002 12:01 PM

Can you also post your server side code for the same .
About | Sitemap | Contact