Hi,
Checkout this code:-
server side
-----------
method 1
BufferedWriter bf=new BufferedWriter(new OutputStreamWriter(m_objClientSocket.getOutputStream(),1);
bf.write("SHUTDOWN");
bf.newLine();
method 2
PrintWriter pw=new PrintWriter(m_objClientSocket.getOutputStream(),true);
pw.println("SHUTDOWN");
setting autoflush=true;
or manually flushing using pw.flush();
----------------
handler code
-----------
public void run(){
BufferedReader br=new BufferedReader(new InputStreamReader(m_objSocket.getInputStream()));
String l_strMessage="";
while(true)
{
if((l_strMessage=br.readLine())!=null)
{
if(l_strMessage.equalsIgnoreCase("SHUTDOWN"))
{
System.out.println("breaking out.");
break;
}
}
}
}
I am getting a flushing problem.
I am spawning a threaded handler from the server side where I pass the socket reference to handle the communication.
On the server side, while shutting down I tried the two methods I pasted above to close client sockets(handler)
thread .But the problem persists.
I am unable to receive the "SHUTDOWN" string at the client end using either of the two methods above.
Kindly advice.
Regards,
Anand Kapadi