import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
class Awtschat extends Frame implements ActionListener
{
TextField t1;
Button b1;
ServerSocket ss;
Socket s;
Scanner sc;
DataOutputStream dos;
DataInputStream dis;
String msg;
Label l1,l2;
Awtschat() throws Exception
{
setVisible(true);
setSize(600,600);
t1=new TextField(50);
b1=new Button("send");
l1=new Label("Client");
l2=new Label();
setLayout(new FlowLayout());
add(l1);
add(l2);
add(t1);
add(b1);
b1.addActionListener(this);
ss=new ServerSocket(5000);
sc=new Scanner(System.in);
s=ss.accept();
dos=new DataOutputStream(s.getOutputStream());
dis=new DataInputStream(s.getInputStream());
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
try
{
String reply=(String)dis.readUTF();
l2.setText(reply);
msg=t1.getText();
dos.writeUTF(msg);
t1.setText("");
}
catch(Exception e){}
}
}
public static void main(String a[]) throws Exception
{
Awtschat ob=new Awtschat();
}
}
Awtcchat.java
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
NR CLASSES, PUNE (8796064387/90)
class Awtcchat extends Frame implements ActionListener
{
TextField t1;
Button b1;
Socket s;
Scanner sc;
DataOutputStream dos;
DataInputStream dis;
String msg;
Label l1,l2;
Awtcchat() throws Exception
{
setVisible(true);
setSize(600,600);
t1=new TextField(50);
b1=new Button("send");
l1=new Label("Sever");
l2=new Label();
setLayout(new FlowLayout());
add(l1);
add(l2);
add(t1);
add(b1);
b1.addActionListener(this);
s=new Socket("localhost",5000);
sc=new Scanner(System.in);
dos=new DataOutputStream(s.getOutputStream());
dis=new DataInputStream(s.getInputStream());
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
try
{
msg=t1.getText();
dos.writeUTF(msg);
t1.setText("");
String reply=(String)dis.readUTF();
l2.setText(reply);
}
catch(Exception e){}
}
}
public static void main(String a[]) throws Exception
{
Awtcchat ob=new Awtcchat();
}
NR CLASSES, PUNE (8796064387/90)
}