Hello everyone.
I'm not sure what I should be trying to use here but I looked in the API and I think this is the closet thing to what I need.
What i'm trying to do is the following:
Everytime I send somthing from a client to a socket or vice versa I want to do the following:
Open the socket to send the String to the server
Like this:
outputServ = new Socket("localhost", 1234);
//Setting up channel to send data to outputserv
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(outputServ
.getOutputStream()));
Now once I send that string to the server I need to wait for acknowledgment from that server that yes it got the String, and to send the next string, if it didn't get the string, resend it. So either way before I send the next string through the socket I need to get that acknowledgement, weither its a good or bad one. But I would like to set a time to wait for a response from the server.
So I set up my InputStreamWriter...
BufferedReader in = new BufferedReader(new InputStreamReader(
outputServ.getInputStream()));
So can I set code to say, if in.read() doesn't get any type of value back from the server within 10 seconds to resend the message through the output stream, (out) ?
I realize TCP does something similar but we must follow this protocol so customers can't complain if somthing bad does happen, i'm just a co-op at this company so I basically have to follow what they say.
I found this, I think it might help but I wasn't sure how to apply it:
12.1.4.1. SO_TIMEOUT
The SO_TIMEOUT option sets a timer on all I/O methods of a socket that block so that you don't have to wait forever if they don't return. This works for operations such as accept() on server sockets and read() or write() on all sockets. If the timer expires before the operation would complete, an InterruptedIOException is thrown. You can catch the exception and continue to use the socket normally if it is appropriate, or you can take the opportunity to bail out of the operation.
Could I catch that excpetion if it does time out and in that exception block some how tell it to resend (write) the string to the socket again?