package com.itycl.net; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.SocketException; public class UdpSendDemo2 { public static void main(String[] args) throws Exception { UdpSendDemo2 usd=new UdpSendDemo2 (); usd.send(); } void send() throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in));//读取键盘上输入的数据 DatagramSocket ds=new DatagramSocket();//建立一个数据包
String line=null; while((line=br.readLine())!=null) { byte[] buf=line.getBytes(); DatagramPacket dp=new DatagramPacket(buf,buf.length,InetAddress.getByName("localhost"),9632);/
/把封装好的数据包发送到目的端口的目的应用程序上 ds.send(dp);//发送数据 } ds.close();//关闭传输资源 } }
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.bianchenghao6.com/java-jiao-cheng/14205.html