Why does this Exception Occur? networking (Connection Refused)
<p>*In this program i have tried to make my pc both server and client. *The  error that i get is "Connection Refused"</p>

<p>This is my program:</p>

<pre><code>    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    class chatboxClient {
    JFrame fr;
    JPanel p;
    JButton send;
    JTextArea ta;
    JRadioButton rb;

     chatboxClient() {
     new chatboxServer();
     fr=new JFrame("ChatBox_CLIENT");
     p=new JPanel();
     send=new JButton("send");
     ta=new JTextArea();
     ta.setRows(20);
     ta.setColumns(20);
     rb=new JRadioButton("Connect");               // action listener for connect
     rb.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent ae) {
       connectActionPerformed(ae); 
      }
    });
    fr.add(p);
    p.add(ta);
    p.add(rb);
    p.add(send);
    fr.setSize(500,500);
    fr.setResizable(false);
    fr.setVisible(true);
   }

    public void connectActionPerformed(ActionEvent ae) {
     try {
       InetAddress address=InetAddress.getLocalHost();
       Socket s=new Socket(address,3000); // create connection with port number 3000 of server 
        if(s.isConnected()==true) {
         JOptionPane.showMessageDialog(new JFrame(),"Connection successfully Established");
        } else {
           JOptionPane.showMessageDialog(new JFrame(),"Error Creating Connection");
          }
     } catch(Exception exc) {
        JOptionPane.showMessageDialog(new JFrame(),exc); // line A
       }
    }

    public static void main(String args[]) {
     new chatboxClient();
    }
   }
</code></pre>

<p><strong>SERVER SIDE:</strong>   </p>

<pre><code>    import java.awt.*;
    import java.net.*;
    import javax.swing.*;
    import java.awt.event.*;
    class chatboxServer {
    JFrame fr;
    JPanel p;
    JTextArea ta;
    JButton send;

    chatboxServer() {
    fr=new JFrame("ChatBox_SERVER");
    p=new JPanel();
    ta=new JTextArea();
    ta.setRows(20);
    ta.setColumns(20);
    send=new JButton("send");
    fr.add(p);
    p.add(ta);
    p.add(send);
    fr.setVisible(true);
    fr.setSize(500,500);
    fr.setResizable(false);
   }

    public static void main(String args[]) {
     new chatboxServer();
    }
   }
</code></pre>

<p><strong>Here I get Exception (When i press connect) corresponding to the only try statement that i have.</strong> <em>(Labeled A)</em>
<strong>What is the reason that i am getting exception?</strong> <em>Note: chatboxServer() is a class defined in the same directory.</em></p>

<p>Through this program i want that message typed in one window goes to another window.I have made my pc both server and client.</p>
