Add timeout in receiving message - socket
<p>I have method for sending message over socket and receiving answer. How to put timer, if there is no answer for example 1 sec to put information timeout ?</p>

<pre><code>public boolean SendForceMessage(final ForceMessageTCP message) {
    boolean result = true;
    System.out.println("******************SendForceMessage**********************************");
    new Thread() {
        public void run() {
            try {
                System.out.println("IPADDRESS="+ipAddress);
                System.out.println("PORT="+port);
                System.out.println("Is reachable="+Ping());

                for(int i=0;i&lt;message.ToBytes().length;i++)
                    System.out.println("FRAGMENT["+i+"]="+message.ToBytes()[i]);

                socket = new Socket(ipAddress, port);
                OutputStream socketOutputStream = (OutputStream) socket
                        .getOutputStream();
                socketOutputStream.write(message.ToBytes());

                InputStream socketInputStream=(InputStream)socket.getInputStream();
                byte[] buffer=new byte[256];
                int numberReceived=socketInputStream.read(buffer);
                if(numberReceived!=-1)
                    new FDResponseMessage(buffer);


                socket.close();
            } catch (UnknownHostException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }.start();

    return result;
}
</code></pre>
