client hanging when server is recycled.
Hi,
I wrote a socket client program that connects to a socket server. This is what I'm doing:
-I'm opening a socket connection
-I'm writing an initial request to the output stream of that socket
-Then, while true, I create an input stream of that socket and get information off that stream
It all works fine, but when the socket server goes down, my input stream hangs. In other words, when the socket server goes down, my client does not come out of the while true loop.
So, how can I close my input stream? How can I know when the server socket went down?
Thanks,
RR
If you are interested in the code:
publicclass SequentialStats{
publicstaticvoid main (String[] args)
throws UnknownHostException, IOException, InterruptedException{
//create a socket
Socket sock =new Socket("es2a208d", 30100);
//open an output stream
BufferedOutputStream outStr =new BufferedOutputStream(sock.getOutputStream());
//initialization request
byte[] initRequest =newbyte[]{0, 8, 0, 1,'1','5','0','5'};
//write the request to the output stream
outStr.write(initRequest);
//flush the stream
outStr.flush();
while(true){
BufferedInputStream bis =new BufferedInputStream(sock.getInputStream());
byte[] barr =newbyte[1948];
bis.read(barr, 0, 1948);
ByteArrayInputStream bais =new ByteArrayInputStream (barr, 0, 1948);
DataInputStream distrm =new DataInputStream (bais);
System.out.println ("MsgSize = " + distrm.readShort());
System.out.println ("MsgType = " + distrm.readShort());
bais.close(); distrm.close();
}
}
}
Message was edited by:
rrvvg_1976

