Am working in the Socket Programing, My application continuously reads the data packet from socket,
sometimes read method is giving 0 value. As per my knowledge the read method of the InputStream will throw IOException if the socket is closed and if data is not available it will give zero.My issue is how to check the socket connection status whether is alive or not and check whether the data is available.
If i get the solution that will be the great help for me..
I had a look into the API i saw the below point also.
*If there are no bytes buffered on the socket, or all buffered bytes have been consumed by read, then all subsequent calls to read will throw an IOException.
in my application i need to send some signaling message to the serversocket to send the data or ack. that time am checking the for exception (IOException) if that occurs am closing an reconnecting the connection. I dont know whether clocsing and reconnecting is good solution. if connection it meaning less to close the connection which is already closed. please give me some suggestion
I have come across so many blogs and forums but all little bit confused.
Thamaiyanthi Pitchaimuthu wrote:Hi Joe,
I dont know whether clocsing and reconnecting is good solution. if connection it meaning less to close the connection which is already closed. please give me some suggestion
My gut feeling is that invoking close() on a closed socket will throw an exception. Of course, the socket closing probably isn't the only reason a socket read would throw an exception, so you should probably try to close it in any event.
Joined: Aug 20, 2010
Am closing and opening the socket whenever exception occurs.