hi , this s a prog tat i ve written for tcp socket communication between client and server. It works as such, but when i converted it to work as an applet, it dint work.pl point out my errors..


//client program


import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class client4 extends Applet implements ActionListener
{
Button send;
int i=0;
TextField t1;
Socket s;
BufferedReader br;
PrintStream p;
Label l1;
public void init()
{
l1=new Label("enter msg");
add(l1);
t1=new TextField(20);
add(t1);
send=new Button("Send");
send.addActionListener(this);
add(send);
try
{
s=new Socket("localhost",2000);
BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintStream p=new PrintStream(s.getOutputStream());
}
catch(Exception e){}
}
public void actionPerformed(ActionEvent e)
{
String msg=new String();
if(e.getSource()==send)
{

try
{
msg=t1.getText();
p.println(msg);
if(msg.equals("logout"))
{
s.close();
}
getGraphics().drawString("CLIENT : "+msg+"\n",20,200+i);
msg=br.readLine();
i+=10;
getGraphics().drawString("SERVER : "+msg+"\n",20,200+i);
i++;
}
catch(Exception exp){}

}
}
}



//server prog
import java.io.*;
import java.net.*;
import java.awt.*;
import javax.swing.*;
public class server4 extends JApplet implements ActionListener
{
JButton send;
int i=0;
JTextField t1;
ServerSocket sock;
Socket s;
BufferedReader br;
PrintStream p;
JLabel l1;
public void init()
{
l1=new JLabel("enter msg");
getContentPane().add(l1);
t1=new JTextField(20);
getContentPane().add(t1);
send=new JButton("Send");
send.addActionListener(this);
getContentPane().add(send);
try
{
sock=new ServerSocket(2000);
s=sock.accept();
BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintStream p=new PrintStream(s.getOutputStream());
}
catch(Exception e){}
}
public void actionPerformed(ActionEvent e)
{
String msg=new String();
if(e.getSource()==send)
{

try
{
msg=br.readLine();
//msg="hello";
getGraphics().drawString("CLIENT : "+msg+"\n",20,200+i);
i+=10;
msg=t1.getText();
if(msg.equals("logout"))
{
s.close();
sock.close();
}
p.println(msg);
}
catch(Exception exp){}
getGraphics().drawString("SERVER : "+msg+"\n",20,200+i);
i+=10;
}
}
}