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

Discussion in 'Java' started by goyal_85, Jul 7, 2010.

  1. goyal_85

    goyal_85

    Joined:
    Jun 11, 2010
    Messages:
    1
    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
    goyal_85, Jul 7, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hazzard
    Replies:
    1
    Views:
    462
    Hazzard
    Apr 2, 2004
  2. Joey
    Replies:
    1
    Views:
    790
    =?Utf-8?B?aGVpbg==?=
    Jan 3, 2006
  3. Maria
    Replies:
    10
    Views:
    606
    Mark McIntyre
    Feb 4, 2004
  4. krithiga81@yahoo.com

    weak pull up and pull down

    krithiga81@yahoo.com, Jun 26, 2006, in forum: VHDL
    Replies:
    2
    Views:
    2,144
    Mike Treseler
    Jun 28, 2006
  5. matt
    Replies:
    1
    Views:
    245
    George Ogata
    Aug 6, 2004
Loading...

Share This Page