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);
}
}

and what error are you getting?

I guess it's a security error and that the OP doesn't understand about applet security restrictions, an issue which is quite simple to understand really but does require reading the documentation and maybe doing a bit of research (all the information if publicly and easily available so I won't copy it here).

and what error are you getting?

it is showing two errors, that is in front of each of TheServer() and TheClient() and prompting that an exception must be thrown

hey u r using getLocalHost() method which gives u access to only your pc so if u want to try it in LAN then u need to use metnod connect() and give IP of NAME of PC which u want to connect.......

and what error did u got????

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.