java - Why does this Exception Occur? networking (Connection Refused) -


* In this program, I have tried to make both my server and client on my PC. * The error I get is "Connection is declined"

This is my program:

  import java.awt. *; Import javax.swing *; Import java.awt.event. *; Import Java.net *; Import java.io * *; Class chatbox client {JFrame fr; JPNl P; Send pocket JTextArea ta; JRDO Button RB; ChatboxClient () {new chatbox server (); Fr = new JFrame ("ChatBox_CLIENT"); P = new zpn (); Send = New Payton ("Send"); Ta = new JTextArea (); Ta.setRows (20); Ta.setColumns (20); RB = new JRDO button ("Connect"); // connector rb.addActionListener for action listener (new ActionListener) {public zero action action (action AE) {connectActionPerformed (ae);}}); Fr.add (p); P.add (ta); P.add (rb); P.add (send); Fr.setSize (500,500); Fr.setResizable (wrong); Fr.setVisible (true); } Public Zero Connect operation (Action AE) {try {InetAddress address = InetAddress.getLocalHost ()} Socket S = new socket (address, 3000); // If you make a connection with port number 3000 of the server (s.isconnected () == true) {JOptionPane.showMessageDialog (new JFrame (), "the connection established successfully"); } Else {JOptionPane.showMessageDialog (new JFrame (), "Error creating connection"); }} Hold (Exception Ax) {JOptionPane.showMessageDialog (New JFrame (), exc); // line A}} public static zero major (string agre []) {new chatboxClient (); }}   

Server Side:

  Import java.awt. *; Import Java.net *; Import javax.swing *; Import java.awt.event. *; Class chatbox server {JFrame fr; JPNl P; JTextArea ta; Send pocket Chatbox server () {fr = new JFrame ("ChatBox_SERVER"); P = new zpn (); Ta = new JTextArea (); Ta.setRows (20); Ta.setColumns (20); Send = New Payton ("Send"); Fr.add (p); P.add (ta); P.add (send); Fr.setVisible (true); Fr.setSize (500,500); Fr.setResizable (wrong); } Public static zero principal (string agre []) {new chatboxServer (); }}   

An exception is available here (when I press connect) the only one is in line with the statement. (label A) What's the reason that I'm getting an exception? Note: The chatbox server () is a class defined in the same directory.

Through this program, I want to send a message typed in a window to another window. I have made my PC both server and client.

If you do not believe us that when we say that denial of connection means that If no server is listening on the port, you can only do Google for it. 3,620,000 hits

Comments