相较于TCP,UDP的效率更高,今天我们来简单实现UDP双人聊天。
大概的逻辑思路是这样的。
最后两块的代码时核心代码,前两个可不看!!
/**
*
*实现界面
*/
package cmo.demo;
import java.awt.Button;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class MainFrame {
static JTextArea area_show=new JTextArea();
static JTextArea area_send=new JTextArea();
static String date;
static SimpleDateFormat df;
public void init() {
JFrame frame=new JFrame();
frame.setSize(800,800)