java中UDP文件传输怎么实现?
2个回答
展开全部
//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();
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |