This is the code i wrote.(it works properly for server to one client communication)
public class server
{
Socket s;
JFrame fr;
JTextArea ta;
JTextArea tb;
JButton b;
JPanel p;
BufferedReader br;
PrintWriter pw;
ServerSocket ss;
server()
{
fr=new JFrame("Client Window");
p=new JPanel();
b=new JButton("Send Data");
ta=new JTextArea(3,50);
tb=new JTextArea(30,50);
b.addActionListener(new sending());
p.add(ta);
p.add(b);
p.add(tb);
(fr.getContentPane()).add(p);
fr.setSize(400,300);
fr.setVisible(true);
}
public static void main(
String a[])throws Exception
{
server x=new server();
x.makeCon();
x.createProcess();
Thread.currentThread().sleep(500);
}
void createProcess()
{
Thread t=new Thread(new clientread());
t.start();
}
void makeCon()
{
try
{
ss=new ServerSocket(3500);
s=ss.accept();
br=new BufferedReader(new InputStreamReader(s.getInputStream()));
pw=new PrintWriter(s.getOutputStream());
System.out.println("Connection Established With client");
}
catch(Exception e)
{
}
}
class sending implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
try
{
pw.println(ta.getText());
pw.flush();
ta.setText("");
ta.requestFocus();
}
catch(Exception e)
{
}
}
}
class clientread implements Runnable
{
public void run()
{
String s;
try
{
while((s=br.readLine())!=null)
{
tb.append(s+"\n");
}
}
catch(Exception e)
{
}
}
}
}