java一对一聊天代码 java聊天程序代码

大家有没有基于一对一聊天的最简单的java聊天代码先运行服务端 再运行客户端就能对话java一对一聊天代码了
服务端
package Liaotian;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class fwjiemian extends Frame implements ActionListener{
JTextArea lt;
TextField sr;
Button fs;
Panel xia;
ServerSocket ss;
Socket s;
BufferedReader br;
PrintWriter pw;
BufferedReader in;
public fwjiemian(){
lt=new JTextArea();
lt.setLineWrap(true);
sr=new TextField();
fs=new Button("发送");
xia=new Panel(new GridLayout(1,2));
xia.add(sr);
xia.add(fs);
this.add(lt);
this.add(xia,BorderLayout.SOUTH);
this.setResizable(false);
this.setSize(400, 500);
this.setLocation(350, 100);
this.setTitle("服务器");
this.setVisible(true);
fs.addActionListener(this);
//创建客户端+接受消息
try {
lt.setFont(newjava.awt.Font("宋体",0,15));
ss=new ServerSocket(8888);
lt.append("服务器已启动java一对一聊天代码,等待客户端接入..."+"\n"+"\n");
s=ss.accept();
lt.append("客户端已接入..."+"\n"+"\n");
while(true){
//获取时间
SimpleDateFormat sm=new SimpleDateFormat("HH:mm:ss");
System.out.println(sm.format(new Date()));
//接受消息
br=new BufferedReader(new InputStreamReader(s.getInputStream()));
String info=br.readLine();
lt.append("☆ 客户端java一对一聊天代码:"+info+""+sm.format(new Date())+"\n"+"\n");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new fwjiemian();
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==fs){
try {
//获取时间
SimpleDateFormat sm=new SimpleDateFormat("HH:mm:ss");
System.out.println(sm.format(new Date()));
//发送消息
String infotokehu=sr.getText();
pw=new PrintWriter(s.getOutputStream(),true);
pw.println(infotokehu);
lt.setFont(newjava.awt.Font("宋体",0,15));
lt.append("

    推荐阅读