java UDP 传输文件
要javaUDP传输文件的源代码,最好附带点说明,急用,谢谢了。发送方的和接收方的都要。不用太复杂,只要能传送几K的小文件就成,也不用缓冲池,不考虑丢包情况。...
要java UDP 传输文件的源代码,最好附带点说明,急用,谢谢了。发送方的和接收方的都要。不用太复杂,只要能传送几K的小文件就成,也不用缓冲池,不考虑丢包情况。
展开
1个回答
展开全部
//Send
DatagramSocket ds = new DatagramSocket(5555, InetAddress
.getByName("10.0.0.1"));
InputStream in = new FileInputStream(new File("a.txt"));
byte[] b = new byte[10240];
int c = in.read(b);
in.close();
DatagramPacket dp = new DatagramPacket(b, c);
ds.send(dp);
//Receive
DatagramSocket ds2 = new DatagramSocket(5555);
DatagramPacket dp2 = new DatagramPacket(b,b.length);
ds2.receive(dp2);
OutputStream out=new FileOutputStream(new File("out.txt"));
out.write(dp2.getData());
out.close();
DatagramSocket ds = new DatagramSocket(5555, InetAddress
.getByName("10.0.0.1"));
InputStream in = new FileInputStream(new File("a.txt"));
byte[] b = new byte[10240];
int c = in.read(b);
in.close();
DatagramPacket dp = new DatagramPacket(b, c);
ds.send(dp);
//Receive
DatagramSocket ds2 = new DatagramSocket(5555);
DatagramPacket dp2 = new DatagramPacket(b,b.length);
ds2.receive(dp2);
OutputStream out=new FileOutputStream(new File("out.txt"));
out.write(dp2.getData());
out.close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询