Android 连接TFTP服务器
服务器端:搭建环境:w10 64位系统,服务器为tftp64:
Current Directory 为服务器的根目录,存放要下载的文件。
Server interface 是服务器的端口
下面选择Tftp Server 因为这里我们要做Tftp服务器。
Tftp 下载连接 http://tftpd32.jounin.net/
下载完成直接安装就行

127.0.01 是本机的ip地址 端口口号 69 服务器就配置完成了。
在电脑端测试服务器是否完成

已经配置完成了,并且可以连接
下面开始手机客户端代码实现了
连接tftp 使用的是一个commons-net-3.6.jar 里面的 TFTPClient
jar 下载 http://commons.apache.org/proper/commons-net/download_net.cgi

TFTP服务器的端口是69
public final class TFTPExample
{static final String USAGE ="Usage: tftp [options] hostname localfile remotefile\n\n" +"hostname   - The name of the remote host [:port]\n" +"localfile  - The name of the local file to send or the name to use for\n" +"\tthe received file\n" +"remotefile - The name of the remote file to receive or the name for\n" +"\tthe remote server to use to name the local file being sent.\n\n" +"options: (The default is to assume -r -b)\n" +"\t-t timeout in seconds (default 60s)\n" +"\t-s Send a local file\n" +"\t-r Receive a remote file\n" +"\t-a Use ASCII transfer mode\n" +"\t-b Use binary transfer mode\n" +"\t-v Verbose (trace packets)\n";public static void TftpUtils(Context context){boolean receiveFile = true, closed;int transferMode = TFTP.BINARY_MODE, argc;String arg, hostname, localFilename, remoteFilename;final TFTPClient tftp;int timeout = 60000;boolean verbose = false;hostname = "192.168.31.10:69";localFilename = Environment.getExternalStorageDirectory().getAbsolutePath()+"/test1.rar";Log.i("localFilename", localFilename);remoteFilename = "test.rar";// Create our TFTP instance to handle the file transfer.if (verbose) {tftp = new TFTPClient() {@Overrideprotected void trace(String direction, TFTPPacket packet) {System.out.println(direction + " " + packet);}};} else {tftp = new TFTPClient();}// We want to timeout if a response takes longer than 60 secondstftp.setDefaultTimeout(timeout);// We haven't closed the local file yet.closed = false;// If we're receiving a file, receive, otherwise send.if (receiveFile){closed = receive(transferMode, hostname, localFilename, remoteFilename, tftp);} else {// We're sending a file// closed = send(transferMode, hostname, localFilename, remoteFilename, tftp);}System.out.println("Recd: "+tftp.getTotalBytesReceived()+" Sent: "+tftp.getTotalBytesSent());if (!closed) {System.out.println("Failed");System.exit(1);}System.out.println("OK");}private static boolean send(int transferMode, String hostname, String localFilename, String remoteFilename,TFTPClient tftp) {boolean closed;FileInputStream input = null;// Try to open local file for readingtry{input = new FileInputStream(localFilename);}catch (IOException e){tftp.close();System.err.println("Error: could not open local file for reading.");System.err.println(e.getMessage());System.exit(1);}open(tftp);// Try to send local file via TFTPtry{String [] parts = hostname.split(":");if (parts.length == 2) {tftp.sendFile(remoteFilename, transferMode, input, parts[0], Integer.parseInt(parts[1]));} else {tftp.sendFile(remoteFilename, transferMode, input, hostname);}}catch (UnknownHostException e){System.err.println("Error: could not resolve hostname.");System.err.println(e.getMessage());System.exit(1);}catch (IOException e){System.err.println("Error: I/O exception occurred while sending file.");System.err.println(e.getMessage());System.exit(1);}finally{// Close local socket and input fileclosed = close(tftp, input);}return closed;}private static boolean receive(int transferMode, String hostname, String localFilename, String remoteFilename,TFTPClient tftp) {boolean closed;FileOutputStream output = null;File file;file = new File(localFilename);// If file exists, don't overwrite it.if (file.exists()){System.err.println("Error: " + localFilename + " already exists.");System.exit(1);}// Try to open local file for writingtry{output = new FileOutputStream(file);}catch (IOException e){tftp.close();System.err.println("Error: could not open local file for writing.");System.err.println(e.getMessage());System.exit(1);}open(tftp);// Try to receive remote file via TFTPtry{String [] parts = hostname.split(":");if (parts.length == 2) {tftp.receiveFile(remoteFilename, transferMode, output, parts[0], Integer.parseInt(parts[1]));} else {tftp.receiveFile(remoteFilename, transferMode, output, hostname);}}catch (UnknownHostException e){System.err.println("Error: could not resolve hostname.");System.err.println(e.getMessage());System.exit(1);}catch (IOException e){System.err.println("Error: I/O exception occurred while receiving file.");System.err.println(e.getMessage());System.exit(1);}finally{// Close local socket and output fileclosed = close(tftp, output);}return closed;}private static boolean close(TFTPClient tftp, Closeable output) {boolean closed;tftp.close();try{if (output != null) {output.close();}closed = true;}catch (IOException e){closed = false;System.err.println("Error: error closing file.");System.err.println(e.getMessage());}return closed;}private static void open(TFTPClient tftp) {try{tftp.open();}catch (SocketException e){System.err.println("Error: could not open local UDP socket.");System.err.println(e.getMessage());System.exit(1);}}}

android 连接tftp 服务器相关推荐

  1. android 连接服务器

    2019独角兽企业重金招聘Python工程师标准>>> 下面就几个小点做概要说明,另外,北风网的<零基础android课程>中对android平台中客户端与web服务器( ...

  2. 【Android RTMP】RTMPDump 推流过程 ( 独立线程推流 | 创建推流器 | 初始化操作 | 设置推流地址 | 启用写出 | 连接 RTMP 服务器 | 发送 RTMP 数据包 )

    文章目录 安卓直播推流专栏博客总结 一. Java 层传入的 RTMP 推流地址处理 二. RTMPDump 推流线程 三. 创建 RTMP 对象 四. 初始化 RTMP 对象 五. 设置 RTMP ...

  3. 【嵌入式开发】嵌入式 开发环境 (远程登录 | 文件共享 | NFS TFTP 服务器 | 串口连接 | Win8.1 + RedHat Enterprise 6.3 + Vmware11)

    作者 : 万境绝尘 博客地址 : http://blog.csdn.net/shulianghan/article/details/42254237 一. 相关工具下载 嵌入式开发工具包 : -- 下 ...

  4. android linux网络连接,Android和Linux服务器之间的TCP连接

    我正在编写一个代码,需要每秒从Android移动设备向台式计算机(linux服务器)发送数据.由于数据经常发送,通过Http命中无法实现(因为会消耗时间),所以Tcp通信似乎是更好的选择,因为andr ...

  5. android与web服务器建立连接失败,Android websocket连接失败

    我正在开发一个简单的应用程序,它只是应该连接到websocket服务器并发送简单的文本消息.我使用nv-websocket-client作为websocket的库.我似乎无法连接到服务器.我使用wir ...

  6. Android连接SQLServer详细教程(数据库+服务器+客户端),并在微软Azure云上搭建云服务

    Android连接SQLServer详细教程(数据库+服务器+客户端),并在微软Azure云上搭建云服务 参考博客:http://blog.csdn.net/zhyl8157121/article/d ...

  7. Android客户端与服务器连接

    一.实验名称 Android客户端与服务器连接. 二.实验背景 2.1需求分析 1.服务端使用JSON解析客户端的请求数据 2.客户端通过HttpClient对象访问服务器,向服务器发送http请求. ...

  8. Android连接SQLServer详细教程(数据库+服务器+客户端)

    本文为原创,如果转载请注明出处 http://blog.csdn.net/zhyl8157121/article/details/8169172 其实之前发过一篇这样的博文http://blog.cs ...

  9. Android Studio连接云服务器数据库

    Android Studio连接云服务器数据库 写在开始 1.Navicat连接云服务器数据库 2.MyEclipse开发服务端servlet的相关步骤 Android Studio端代码编写 写在开 ...

  10. wpa_supplicant无线网络配置imx6ull以及搭建tftp服务器

    文章目录 1- wpa_supplicant介绍 2- wpa_supplicant无线网络配置 (1)手动无线网络配置 (2)开机执行脚本自动无线网络配置 3- tftp介绍 4- tftp服务器搭 ...

最新文章

  1. Android 百度鹰眼轨迹SDK(v2.1.6)
  2. Comparable接口和Comparator接口的比较
  3. 老司机的应用级监控——spring?actuator
  4. java多线程 生产者消费者_java多线程之生产者消费者经典问题 - 很不错的范例
  5. 飞信SDK内容【转载】
  6. 查看python进程_[原创] 如何查看一个Python进程在”干什么”: py-spy 来帮忙 – 编码无悔 / Intent Focused...
  7. ffmpeg输出yuv的函数堆栈(h264)
  8. US-CERT 公布近三年遭利用频率最高的十大安全漏洞
  9. C# Programming Study #2
  10. Git来回切换版本的时候,pom文件变黄,每次都需要重新添加到maven以及修改后文件不生效的解决方法
  11. PNP三极管的一个暗黑技巧
  12. 示波器基本原理之六:示波器的基本控制
  13. shardingsphere源码分析(四)-- 改写引擎
  14. oracle设置事务隔离级别为读已提交,oracle的事务隔离级别和读一致性
  15. 微信公众号开发本地环境搭建
  16. 3dmaxs坐标轴不显示灰色显示(没有坐标轴箭头)
  17. java 函数表_C语言、Java语言的符号表区别和特点是什么?分别是如和处理函数参数的?...
  18. 期货外接看穿式技术方面问答总结
  19. 【爬虫】牛客网简易爬虫(二)用Selenium看看你投过简历的公司这个月哪些有笔试+笔试时间
  20. 天泉湖酒店式养生社区服务中心漏电火灾监控系统的设计与应用

热门文章

  1. kafka不消费:9092 (id: 0 rack: null)
  2. (转发)贼牛逼的双数据源切换 赞一个 PS:关于最后事物无法切换的问题 也有解决方案 后续补上
  3. 获取本机局域网IP地址
  4. 王家林 大数据Spark超经典视频链接全集[转]
  5. 2021-06-16 解决MDK5使用STLINK下载不进去程序报错的问题
  6. 程序员的终极幻想(三):做一只小小的蜗牛
  7. 如何修改Windows(可移植)桌面文件夹图标
  8. 计算机专业考研2021,2021考研:计算机专业考研方向有哪些?
  9. macOS 安装 aircrack-ng 破解 wifi,hashcat ,OnlineHashCrack,在线破解握手包
  10. Bye Bye Blemish掰掰布楠妮,轻松祛痘,告别磨皮滤镜!