Can I set a time out for BufferReader?
<p>The first time I made a method to read data from my chat server, it frooz.  I found out I had the wrong port number and it was freezing at 
new BufferedReader(new InputStreamReader(conn.getInputStream()));</p>

<p>Is there a way to have a time out so my program does not freez on a network error? I'm assuming there must be,
the complete methed</p>

<pre><code>void SendMessage()
        {
            try {


            URL url = new URL("http://50.63.66.138:1044/update");
               System.out.println("make connection");
               URLConnection conn = url.openConnection();
               conn.setDoOutput(true);
               BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));


            //   String line;
               String f=new String("");
               String line=new String();
               while ((line= rd.readLine()  ) != null) {
                 f=f+line;
                 f+="\n";
               }
               mUsers.setText(f);

        } catch (Exception e) {

               System.out.println("exception");
               System.out.println(e.getMessage());
           }

        }
}
</code></pre>
