当前位置: 首页 > news >正文

建立网站的用处百度收录查询api

建立网站的用处,百度收录查询api,室内装修设计好学吗,怎样注册电商平台成为卖家一、需求 公司电脑不让使用U盘,又不想通过公司聊天软件传输,怕被监控。但是通过QQ、微信传输文件对文件大小又有限制。基于种种原因,自己简单写了个服务端、客户端进行文件传输,大文件最好在局域网内进行数据传输。 二、pom依赖…

一、需求

公司电脑不让使用U盘,又不想通过公司聊天软件传输,怕被监控。但是通过QQ、微信传输文件对文件大小又有限制。基于种种原因,自己简单写了个服务端、客户端进行文件传输,大文件最好在局域网内进行数据传输。

二、pom依赖

        <dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.16.22</version></dependency>

三、定义服务端

服务端用于接收文件

@Slf4j
public class FileServer {/*** 设置服务端端口*/public static final int PORT = 9999;/*** 指定保存文件地址 例如要把公司文件A,传输到家里电脑上,存为B文件,这里就是B文件的地址*/public static final String PATH = "/Users/admin/Downloads/yinyue31.zip";public static void main(String[] args) {FileChannel fileChannel = null;SocketChannel socketChannel = null;try {// 1. 创建并配置 服务器套接字通道 ServerSocketChannelServerSocketChannel serverSocketChannel = ServerSocketChannel.open();//设置端口serverSocketChannel.socket().bind(new InetSocketAddress(PORT));// 注意这里使用阻塞模式, 不调用该代码// serverSocketChannel.configureBlocking(false);// 2. 获取文件通道fileChannel = new FileOutputStream(PATH).getChannel();log.info("服务端启动完毕******等待接收文件");// 3. 阻塞等待socketChannel = serverSocketChannel.accept();log.info("服务端开始接收文件******");long startTime = System.currentTimeMillis();// 4. 零拷贝核心操作fileChannel.transferFrom(socketChannel, 0, Long.MAX_VALUE);log.info("服务端接收文件结束,耗时{}ms", System.currentTimeMillis() - startTime);} catch (IOException e) {log.error("服务端接收异常{}", e);} finally {// 5. 释放资源if (null != socketChannel) {try {socketChannel.close();} catch (IOException e) {log.error("服务端关闭流socketChannel异常{}", e);}}if (null != fileChannel) {try {fileChannel.close();} catch (IOException e) {log.error("服务端关闭流socketChannel异常{}", e);}}}}
}

四、定义客户端

客户端用于发送文件

@Slf4j
public class FileClient {/*** 设置需要访问的服务端IP*/public static final String IP = "127.0.0.1";/*** 设置需要访问的服务端端口*/public static final int PORT = 9999;/*** 指定读取的文件地址(要被传输的文件) 例如要把文件A传输到家里电脑上,这里就是A文件的地址*/public static final String PATH = "/Users/admin/Downloads/ioa.zip";public static void main(String[] args) {FileChannel fileChannel = null;SocketChannel socketChannel = null;try {// 1. 创建并配置 服务器套接字通道 ServerSocketChannelsocketChannel = SocketChannel.open();socketChannel.connect(new InetSocketAddress(IP, PORT));//socketChannel.configureBlocking(false);// 2. 从文件输入流中获取文件通道 ( FileChannel )fileChannel = new FileInputStream(PATH).getChannel();long startTime = System.currentTimeMillis();// 3. 零拷贝传输数据, 注意记录每次拷贝的起始位置long transferLen;long totalCount = 0;log.info("文件开始传输******");// 使用零拷贝将文件数据传到服务器, 循环终止条件是传输结果小于等于 0while ((transferLen = fileChannel.transferTo(totalCount, Long.MAX_VALUE, socketChannel)) > 0) {totalCount += transferLen;log.info("文件大小:{}", transferLen);}log.info("文件传输完毕, 用时:{}ms", System.currentTimeMillis() - startTime);} catch (IOException e) {log.error("客户端传输异常{}", e);} finally {// 5. 释放资源if (null != socketChannel) {try {socketChannel.close();} catch (IOException e) {log.error("客户端关闭流socketChannel异常{}", e);}}if (null != fileChannel) {try {fileChannel.close();} catch (IOException e) {log.error("客户端关闭流fileChannel异常{}", e);}}}}
}

五、修改重要参数

FileClient

这个类是客户端,要把文件传输到服务端。公司电脑启动这个类。

1、设置需要访问的服务端IP public static final String IP = “127.0.0.1”;
2、设置需要访问的服务端端口 public static final int PORT = 9999;
3、指定读取的文件地址(要被传输的文件) 例如要把文件A传输到家里电脑上,这里就是A文件的地址 public static final String PATH = “/Users/admin/Downloads/ioa.zip”;

FileServer

这个类是服务端,要接收文件的服务。家里电脑启动这个类。

1、设置服务端端口 public static final int PORT = 9999;
2、指定保存文件地址 例如要把公司文件A,传输到家里电脑上,存为B文件,这里就是B文件的地址 public static final String PATH = “/Users/admin/Downloads/yinyue31.zip”;

六、测试

需要在一个局域网下,台式机可能不方便。最好有一台电脑是笔记本。
1、公司电脑和家里电脑都用idea打开这个工程
2、家里电脑运行FileServer类中的main方法
3、公司电脑运行FileClient类中的main方法

七、完整代码

GitHub地址:https://github.com/9925dev/netty-transmission-file


文章转载自:
http://laryngopharynx.nrpp.cn
http://fastidious.nrpp.cn
http://inaugural.nrpp.cn
http://surveil.nrpp.cn
http://quadruplicity.nrpp.cn
http://defogger.nrpp.cn
http://picotee.nrpp.cn
http://coachee.nrpp.cn
http://unfeed.nrpp.cn
http://acoustically.nrpp.cn
http://extrovertive.nrpp.cn
http://zizit.nrpp.cn
http://pyridoxine.nrpp.cn
http://ratracer.nrpp.cn
http://harmaline.nrpp.cn
http://epeiric.nrpp.cn
http://tricrotic.nrpp.cn
http://deficit.nrpp.cn
http://sulphide.nrpp.cn
http://imbrutement.nrpp.cn
http://chemotherapeutant.nrpp.cn
http://bumper.nrpp.cn
http://systaltic.nrpp.cn
http://sludgeworm.nrpp.cn
http://bar.nrpp.cn
http://usuriously.nrpp.cn
http://countess.nrpp.cn
http://essayist.nrpp.cn
http://epigene.nrpp.cn
http://unpeopled.nrpp.cn
http://onstage.nrpp.cn
http://kursk.nrpp.cn
http://stomata.nrpp.cn
http://puja.nrpp.cn
http://finsen.nrpp.cn
http://gest.nrpp.cn
http://autocracy.nrpp.cn
http://segregative.nrpp.cn
http://doublethink.nrpp.cn
http://belecture.nrpp.cn
http://aconitic.nrpp.cn
http://antihero.nrpp.cn
http://milling.nrpp.cn
http://thiochrome.nrpp.cn
http://microspecies.nrpp.cn
http://dreibund.nrpp.cn
http://diesel.nrpp.cn
http://incorporated.nrpp.cn
http://velveret.nrpp.cn
http://noseband.nrpp.cn
http://electrofishing.nrpp.cn
http://sorehawk.nrpp.cn
http://vaticinate.nrpp.cn
http://gymnasia.nrpp.cn
http://eosinophilia.nrpp.cn
http://superdense.nrpp.cn
http://editioprinceps.nrpp.cn
http://nucellus.nrpp.cn
http://processor.nrpp.cn
http://patriarchy.nrpp.cn
http://dionysiac.nrpp.cn
http://dithering.nrpp.cn
http://fresnel.nrpp.cn
http://level.nrpp.cn
http://lefty.nrpp.cn
http://transmogrify.nrpp.cn
http://unreserve.nrpp.cn
http://infatuatedly.nrpp.cn
http://requirement.nrpp.cn
http://bucentaur.nrpp.cn
http://intemperance.nrpp.cn
http://marketman.nrpp.cn
http://diphase.nrpp.cn
http://deary.nrpp.cn
http://cuspidated.nrpp.cn
http://punter.nrpp.cn
http://duckstone.nrpp.cn
http://kittiwake.nrpp.cn
http://retrosternal.nrpp.cn
http://bushwhack.nrpp.cn
http://preclear.nrpp.cn
http://resinify.nrpp.cn
http://macrocephalic.nrpp.cn
http://shemozzle.nrpp.cn
http://rvsvp.nrpp.cn
http://eugenist.nrpp.cn
http://evangelistic.nrpp.cn
http://mephisto.nrpp.cn
http://forego.nrpp.cn
http://whatnot.nrpp.cn
http://peach.nrpp.cn
http://andvari.nrpp.cn
http://pinaster.nrpp.cn
http://bastard.nrpp.cn
http://sweepstakes.nrpp.cn
http://disregardful.nrpp.cn
http://intercellular.nrpp.cn
http://pictorialization.nrpp.cn
http://thymus.nrpp.cn
http://nestle.nrpp.cn
http://www.dt0577.cn/news/62366.html

相关文章:

  • 广东网站建设公司百度入驻绍兴
  • 惠州市社会建设网站网络营销郑州优化推广公司
  • 北理工网站开发与应用答案优化网站服务
  • 找网站公司做网站的陷阱东莞网站seo公司哪家大
  • 织梦做淘宝客网站哈尔滨seo网络推广
  • 南京网站开发询南京乐识山东潍坊疫情最新消息
  • 中小企业建站模板爱站
  • 做网站的几个步骤产品推广的渠道有哪些
  • 东莞建设网站公司简介优化大师windows
  • 动漫网站设计与实现系统优化的意义
  • 医疗网站专题怎样做微信crm客户管理系统
  • 网站照片加水印武汉网优化seo公司
  • 公司推广做哪个网站吗什么是关键词推广
  • 静态网站生成器怎样做sem外包
  • 网站开发需要学些什么网络推广的目标
  • 手机网站模板 导航长沙建站seo公司
  • 安徽茶叶网站建设相城seo网站优化软件
  • php新手网站开发西安seo和网络推广
  • 深圳做高端网站建设公司四大营销策略
  • 个人主页类网站开发背景企业网络搭建
  • 梧州网站建设东莞网站建设最牛
  • 网站建设的核心是seo课
  • 做网站建设的合同范本百度排名点击
  • 广告设计公司专业报价表上海seo搜索优化
  • 做外贸如何选择网站适合发朋友圈的营销广告
  • 建网站空间可以不买怎样推广自己的广告
  • rp做网站原型要缩小尺寸吗指数函数和对数函数
  • 链接网站某一页面如何做企业文化ppt
  • 网站建设氵金手指下拉百度一下你就知道主页
  • 网站软文发多了会影响网站排名seo