java timer and socket problem
        Posted  
        
            by Guru
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Guru
        
        
        
        Published on 2010-04-20T06:31:13Z
        Indexed on 
            2010/04/20
            6:33 UTC
        
        
        Read the original article
        Hit count: 274
        
Hi there,
I'm trying to make a program which listens to the client input stream by using socket programming and timer
but whenever timer executes.. it gets hanged
Please help me out
here is the code...
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: try
    {
    ServerUserName=jTextField1.getText();
    ss=new ServerSocket(5000);
    jButton1.enable(false);
    jTextArea1.enable(true);
    jTextField2.enable(true);
    Timer t=new Timer(2000, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try
            {
                s=ss.accept();                    
                InputStream is=s.getInputStream();
                DataInputStream dis=new DataInputStream(is);
                jTextArea1.append(dis.readUTF());
            }
            catch(IOException IOE)
            {
            }
                catch(Exception ex)
                {
                    setLbl(ex.getMessage());
                }
            }
        });
    t.start();
    }
    catch(IOException IOE)
    {
    }
}
Thanks in advance
© Stack Overflow or respective owner