I/O blocks in server side thread when i pull off the battery from client side

Joined
Jun 11, 2010
Messages
1
Reaction score
0
hi, i m working on client socket connection. client is a GPRS hardware device. i m receiving request from this client on my serversocket and then opening multiple threads. my problem is that when device/client close the socket then my IO detects that throws an exception but when i put off the battery from the device while sending the request to the serversocket it is blocked without throwing any exception. somebody suggested me to use setSOTimeout() to comeout from the blocking thread.

i have tried Socket.setSOTimeout(int) . but this is not working out in my case. i m sending my code properly. in main class--- try {

serverSocket = new ServerSocket(port);//creating a serversokcet on a port

System.out.println("Server waiting for client on port " +

serverSocket.getLocalPort());

} catch (Exception e) {

e.printStackTrace();

handleExceptions("errorServerSocketOpen.txt", e);

System.exit(0);
}

try {

while (true) {
Socket clientSocket = serverSocket.accept();//accepting the client connection and creating client socket

// clientSocket.setSoTimeout(60000);// this is what i added.timeout on each //client socket opened in threads

new AcceptConnection(clientSocket);//calling the constructor of other //class to open a new thread

System.out.println("constructor called.....");
}

} catch (Exception e) {

handleExceptions("errorClientSocketOpen.txt", e);

}

in other class--- public class AcceptConnection implements Runnable {

public AcceptConnection(Socket socket) {

this.clientSocket = socket;

if (clientSocket != null) {

new Thread(this).start();

}

public void run() {

InputStream inputStream = clientSocket.getInputStream();

DataOutputStream dataOutputStream = new DataOutputStream(clientSocket.getOutputStream());

byte[] mainBuffer = new byte[2048];

int len = -1, totalLength = 0;

debugInfo = " GOING TO READ FROM SOCKET.... " + "\n";

while ((len = inputStream.read(mainBuffer)) > -1) {
totalLength = len;
}//end of while

} }//end of other class

now my problem is that when multiple threads are opened and i send the data from client than after 60 seconds it closes the main socket and stops receiving the data.and a readtimeout error occurs.

please help me out and tell me how my objective could be fulfilled.

thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top