all right i need help to run the java applets my former teacher gave me. they were two..one was called server another was called client. you run the server one on one pc, it asks you to enter the port number. you run the client applet on another pc on the same network and enter the same port number. the both get connected and now you can send messages between these two pcs. that's how my teacher showed me. now i am trying to do that but i am getting an error "java.net.ConnectException : Connection refused : Connect "
now i know it used to work long back and the code has not been modified. but i cannot get it to work now. maybe im missing something? do i put the codes for the applets here? cus i can't find an option to attach something.
ChatClient.java code :
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class ChatClient implements ActionListener{
static JTextArea ta = null;
static JButton b1=null;
static DataInputStream in = null;
static DataOutputStream out = null;
static Socket s = null;
static ServerSocket ss = null;
public ChatClient(){
JFrame jf = new JFrame("Chat Client");
jf.setSize(300,300);
jf.setLocation(150,150);
ta = new JTextArea();
b1 = new JButton("Send");
jf.add("South",b1);
jf.add("North",ta);
b1.addActionListener(this);
jf.setVisible(true);
}
public void actionPerformed(ActionEvent evt){
if(evt.getSource()==b1){
try{
out.writeUTF(ta.getText());
}
catch(Exception e){
System.out.println(e);
}
}
}
public static void main(String[]args){
new ChatClient();
try{
int port = Integer.parseInt(JOptionPane.showInputDialog("Enter port number"));
s = new Socket("127.0.0.1",port);
System.out.println("client is connected");
in = new DataInputStream(s.getInputStream());
out = new DataOutputStream(s.getOutputStream());
while(true){
ta.setText(in.readUTF());
}
}
catch(Exception e){
System.out.println(e);
}
}
}
ChatServer.java code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class ChatServer implements ActionListener{
static JTextArea ta = null;
static JButton b1=null;
static DataInputStream in = null;
static DataOutputStream out = null;
static Socket s = null;
static ServerSocket ss = null;
public ChatServer(){
JFrame jf = new JFrame("Chat Server");
jf.setSize(300,300);
jf.setLocation(50,50);
ta = new JTextArea();
b1 = new JButton("Send");
jf.add("South",b1);
jf.add("North",ta);
b1.addActionListener(this);
jf.setVisible(true);
}
public void actionPerformed(ActionEvent evt){
if(evt.getSource()==b1){
try{
out.writeUTF(ta.getText());
}
catch(Exception e){
System.out.println(e);
}
}
}
public static void main(String[]args){
new ChatServer();
try{
int port = Integer.parseInt(JOptionPane.showInputDialog("Enter port number"));
ss = new ServerSocket(port);
System.out.println("Server start and wait...........");
s = ss.accept();
System.out.println("client is connected");
in = new DataInputStream(s.getInputStream());
out = new DataOutputStream(s.getOutputStream());
while(true){
ta.setText(in.readUTF());
}
}
catch(Exception e){
System.out.println(e);
}
}
}
i REALLY need this to work and i am all confused. please guide me.