daybcast.java

来自「翁剀JAVA语言那门课程的教案 很多人都看多他的视频教程可惜没有ppt的教案」· Java 代码 · 共 32 行

JAVA
32
字号
import java.net*;
import java.util.*;

public class DayBcast {
    DatagramSocket ds;
    DatagramPacket dp;
    InetAddress addr;
    
    public static final int DATTIME_PORT = 1313;
    
    public static void main(String[] args) throws Exception {
        DayBcast db = new DayBcast(args[0]);
        db.go();
    }
    
    public DatBcast(String target) throws Exception {
        addr = InetAddress.getByName(target);
        ds = new DatagramSocket();
    }
    
    public void go() throws Exception {
        byte[] buff;
        for (;;) {
            Thread.sleep(1000);
            System.out.println("Sending");
            String s = (new Date()).toString();
            buff = s.getBytes();
            dp = new DatagramPacket(buff,buff.length,addr,DATTIME_PORT);
            ds.send(dp);
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?