Android安卓 TCP Socket通信实现 静态IP设置,ping通也无法TCP连接,路由表,usb网卡和wifi网卡共存等相关问题

您所在的位置:网站首页 手机typec网卡设置ip Android安卓 TCP Socket通信实现 静态IP设置,ping通也无法TCP连接,路由表,usb网卡和wifi网卡共存等相关问题

Android安卓 TCP Socket通信实现 静态IP设置,ping通也无法TCP连接,路由表,usb网卡和wifi网卡共存等相关问题

2024-05-25 20:43| 来源: 网络整理| 查看: 265

Android TCP通信 前言一、系统端1.开机启动usb0网卡2.开机配置静态ip方法3.补充修改动态IP: 二、PC端1.善用工具查看状态排除问题 三、Android端1.确保Android端和usb模块端在同一个局域网2 注意一下通信细节 四、各种问题命令的思路分析简叙1.用到的命令2异常问题可能原因1.Network is unreachable2.timeout 附加需求1.搞个开机执行的脚本2.在init.rc文件直接添加命令1.找到文件system/core/rootdir/init.rc2. 增加rc文件适配的命令3. 补充个idea,可以将命令写入开机启动的root进程 总结下载

前言

Android设备连接外置usb网卡模块,Android设备想通过TCP连接usb网卡模块的服务,如何开机启动并设置usb网卡模块静态ip,如何解决ping通但TCP还是连不上等问题如何解决?我想这篇文章可以帮助解决所需要的。

一、系统端 1.开机启动usb0网卡

找到系统配置:frameworks/base/core/res/res/values/config.xml

修改:+ eth\\d|usb\\d 2.开机配置静态ip方法

一般网卡ip配置文件是在:"/data/misc/ethernet/ipconfig.txt";但实际没有用户配过,则文件不存在。 所以要先找到文件:frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetConfigStore.java 修改函数:readIpAndProxyConfigurations()

if (networks.size() == 0) { - Log.w(TAG, "No Ethernet configuration found. Using default."); - return new IpConfiguration(IpAssignment.DHCP, ProxySettings.NONE, null, null); + + StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration(); + InetAddress mIpAddr = NetworkUtils.numericToInetAddress("192.168.62.199"); + String[] strs = "255.255.255.0".split("\\.");//mask + int count = 0; + for(String str : strs){ + if(str.equals("255")){ + count++; + } + } + int prefixLength = count*8; + LinkAddress mIpAddress = new LinkAddress(mIpAddr,prefixLength); + InetAddress mGateway = NetworkUtils.numericToInetAddress("192.168.62.77");//getway + ArrayList mDnsServers = new ArrayList();//DNS + mDnsServers.add(NetworkUtils.numericToInetAddress("6.6.6.6"));//dns1 + mDnsServers.add(NetworkUtils.numericToInetAddress("8.8.8.8"));//dns2 + + staticIpConfiguration.ipAddress = mIpAddress; + staticIpConfiguration.gateway = mGateway; + staticIpConfiguration.dnsServers.addAll(mDnsServers); + + IpConfiguration default_config = new IpConfiguration(IpAssignment.STATIC, ProxySettings.NONE, st + writeIpAndProxyConfigurations(default_config); + Log.w(TAG, "No Ethernet configuration found. Using default.default_config="+default_config); + return default_config; } ``` 3.补充修改动态IP: public void setMoveIp(){ try { //对比STATIC,只需要把StaticIpConfiguration赋值为null IpConfiguration config = new IpConfiguration(IpConfiguration.IpAssignment.DHCP, IpConfiguration.ProxySettings.NONE, null, ProxyInfo.buildDirectProxy(null,0)); mEthManager.setConfiguration(config); }catch (Exception e) { e.printStackTrace(); } }


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3