I'm reading some data through socket like socket.readLine() .here the data is getting from flash client.The problem is the readline statement is hanging if the we didnt get the message from client side.I have to wait for 2 or 3 seconds and i have to skipp the readline statement if i didnt get the message from the client side.
Let me know if im not clear
Regards,
Bhagavan
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35254
7
posted
0
Socket does not have a readLine method; what exactly is the code doing?
hi,we want to terminate the readline method after some interval when there is no data from client.
The code we are using is as follows :-
public void run() {
try {
this.socketIn = new BufferedReader(new InputStreamReader(
this.socket.getInputStream()));
this.socketOut = new PrintWriter(this.socket.getOutputStream(),
true);
conn = ConnectionHelper.getConnection();
It's possible that readLine blocks if no terminated line is available, but the stream is not yet closed. If you were using raw streams you could check this with the "available" method.
luri ron
Ranch Hand
Joined: Dec 11, 2008
Posts: 86
posted
0
what need to be done in this case:
1. the readline need to be run in a separate thread: reader thread
2. the main need to join on reader thread within a timeout readerThread.join (timeout). if there is nothing is read (use a flag in your reader thread to do this), throw an exception or some sort tell the caller.
3. close the socket. once the socket is closed, the reader thread will throw an exception. don't close the bufferedreder as the bufferedreader.readline has the lock which will prevent any thread from calling the close.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.