my program freezes when I put this code on a button,

but when I put it in the main it doesn't
what could be the problem?

protected void EstablishClient() {
    try {

        skt = new Socket("some.ip.of.me", 4444);  
        out = new PrintWriter(skt.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(skt.getInputStream()));
        txtRecvd.append("Received string: '" + "\n");

        String fromServer;
        while(!in.ready()){
        try{
            fromServer = in.readLine();
            txtRecvd.append("From Server: " + fromServer + "\n");
            }catch(IOException e){}
        }