a- package udp.communication;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.DatagramPacket;
- import java.net.DatagramSocket;
- import java.net.InetAddress;
- public class Send {
- /**
- * 发送端
- *
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- // 建立数据报对象
- DatagramSocket ds = new DatagramSocket();
- // 封装键盘录入信息
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String line = null;
- // 信息装包
- while ((line = br.readLine()) != null) {
- if("886".equals(line)){
- break;
- }
- DatagramPacket dp = new DatagramPacket(line.getBytes(),
- line.getBytes().length,InetAddress.getByName("192.168.31.248"),10086);
- // 发送包
- ds.send(dp);
- }
- // 释放资源
- }
- }
复制代码
|
|