i am trying to make a chat applet ,first problem is that it is working for only single system,i want to know how to connect it with network and second there is some problem in my code it os showing some error which i am unable to debug.
so help me if you can
byeee
HERE IS THE CODE
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.net.*;
public class chat extends Applet implements ActionListener//,ItemListener
{
public /*static*/ int serverPort = 998;
public /*static*/ int clientPort = 999;
public /*static */int buffer_size = 1024;
public /*static*/ DatagramSocket ds;
public /*static*/ byte buffer[] = new byte[buffer_size];
TextField tf;
TextArea ta;
Button send;
public /*static*/ void TheServer(String d) throws Exception
{
while (true)
{
//for(int i=0;i<d.length;i++)
byte buffer[]=d.getBytes();//(byte)d;
ds.send(new DatagramPacket(buffer,buffer.length,
InetAddress.getLocalHost(),clientPort));
}
}
public /*static*/ void TheClient() throws Exception
{
while(true)
{
DatagramPacket p = new DatagramPacket(buffer,buffer.length);
ds.receive(p);
String temp=new String(p.getData(),0,p.getLength());
//String dd=ta.getText();
ta.setText(ta.getText()+"\n"+temp);
}
}
public void init()
{
//Color c1=new Color(144,90,235);
setBackground(Color.cyan);
setForeground(Color.blue);
setLayout(new FlowLayout(FlowLayout.LEFT,470,50));
tf=new TextField(50);
ta=new TextArea(10,100);
send=new Button("send");
add(ta);
add(tf);
add(send);
send.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if(str.equals("send"))
{
ds = new DatagramSocket(serverPort);
//char a[]=new char[100];
//String q=tf.getText();
//int l=q.length;
//for(int j=0;j<l;j++)
//a[j]=q.charAt(j);
TheServer(tf.getText());
}
ds = new DatagramSocket(clientPort);
TheClient();
}
public void paint(Graphics g)
{
g.drawString("G-CHAT",450,20);
}
}