lwip的tcp断线重连例程_STM32F107+LWIP---如何检查tcp通讯断开?并重新连接
void LwIP_Init(void)
{
struct ip_addr ipaddr; //IP地址
struct ip_addr netmask; //子掩码
struct ip_addr gw; //网关地址
uint8_t macaddress[6]={0,0,0,0,0,1}; //以太网控制器物理地址,即MAC地址
/* Initializes the dynamic memory heap defined by MEM_SIZE.*/
mem_init();
/* Initializes the memory pools defined by MEMP_NUM_x.*/
memp_init();
#if LWIP_DHCP
ipaddr.addr = 0;
netmask.addr = 0;
gw.addr = 0;
#else
IP4_ADDR(&ipaddr, 192, 168, 1, 200);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP4_ADDR(&gw, 192, 168, 1, 1);
#endif
Set_MAC_Address(macaddress);
/* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
struct ip_addr *netmask, struct ip_addr *gw,
void *state, err_t (* init)(struct netif *netif),
err_t (* input)(struct pbuf *p, struct netif *netif))
Adds your network interface to the netif_list. Allocate a struct
netif and pass a pointer to this structure as the first argument.
Give pointers to cleared ip_addr structures when using DHCP,
or fill them with sane numbers otherwise. The state pointer may be NULL.
The init function pointer must point to a initialization function for
your ethernet netif interface. The following code illustrates it's use.*/
netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, ðernet_input);
/* Registers the default network interface.*/
netif_set_default(&netif);
#if LWIP_DHCP
/* Creates a new DHCP client for this interface on the first call.
Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at
the predefined regular intervals after starting the client.
You can peek in the netif->dhcp struct for the actual DHCP status.*/
dhcp_start(&netif);
#endif
/* When the netif is fully configured this function must be called.*/
netif_set_up(&netif);
tcp_client_init();
}
/**
* @brief Called when a frame is received
* @param None
* @retval None
*/
void LwIP_Pkt_Handle(void)
{
/* Read a received packet from the Ethernet buffers and send it to the lwIP for handling */
ethernetif_input(&netif);
}
/**
* @brief LwIP periodic tasks
* @param localtime the current LocalTime value
* @retval None
*/
void LwIP_Periodic_Handle(__IO uint32_t localtime)
{
/* TCP periodic process every 250 ms */
if (localtime - TCPTimer >= TCP_TMR_INTERVAL)
{
TCPTimer = localtime;
tcp_tmr();
}
/* ARP periodic process every 5s */
if (localtime - ARPTimer >= ARP_TMR_INTERVAL)
{
ARPTimer = localtime;
etharp_tmr();
}
#if LWIP_DHCP
/* Fine DHCP periodic process every 500ms */
if (localtime - DHCPfineTimer >= DHCP_FINE_TIMER_MSECS)
{
DHCPfineTimer = localtime;
dhcp_fine_tmr();
}
/* DHCP Coarse periodic process every 60s */
if (localtime - DHCPcoarseTimer >= DHCP_COARSE_TIMER_MSECS)
{
DHCPcoarseTimer = localtime;
dhcp_coarse_tmr();
}
#endif
}
/**
* @brief LCD & LEDs periodic handling
* @param localtime: the current LocalTime value
* @retval None
*/
void Display_Periodic_Handle(__IO uint32_t localtime)
{
/* 250 ms */
if (localtime - DisplayTimer >= LCD_TIMER_MSECS)
{
DisplayTimer = localtime;
#if LWIP_DHCP
/* We have got a new IP address so update the display */
if (IPaddress != netif.ip_addr.addr)
{
/* Read the new IP address */
IPaddress = netif.ip_addr.addr;
/* Display the new IP address */
if (netif.flags & NETIF_FLAG_DHCP)
{
tcp_client_init();
}
}
else if (IPaddress == 0)
{
/* If no response from a DHCP server for MAX_DHCP_TRIES times */
/* stop the dhcp client and set a static IP address */
if (netif.dhcp->tries > MAX_DHCP_TRIES)
{
struct ip_addr ipaddr;
struct ip_addr netmask;
struct ip_addr gw;
dhcp_stop(&netif);
IP4_ADDR(&ipaddr, 192, 168, 1, 8);
IP4_ADDR(&netmask, 255, 255, 255, 201);
IP4_ADDR(&gw, 192, 168, 1, 1);
netif_set_addr(&netif, &ipaddr , &netmask, &gw);
}
}
#endif
}
}
lwip的tcp断线重连例程_STM32F107+LWIP---如何检查tcp通讯断开?并重新连接相关推荐
- 关于tcp断线重连的问题
在工控上经常用到tcp连接,比如串口服务器或某些支持modbustcp协议的仪表等,以前尽量使用串口服务器的虚拟串口功能,现在逐步使用上了tcpserver或tcpclient模式. 搜索了个C++ ...
- tcp 重连 java,TCP断线重连机制
断线重连机制 [java] view plain copy /** * 断线重连机制 * Created by fflin on 2016/5/8. */ public class Reconnect ...
- PHP如何解决swoole守护进程Redis假死 ,mysql断线重连问题?
PHP如何解决swoole守护进程Redis假死 ,mysql断线重连问题? 最近公司有个项目,要举办一个线上活动,我这边负责提供接口记录用户访问记录,与操作记录,由于活动参与人数可能比较多,为了不影 ...
- Netty是如何实现TCP心跳机制与断线重连的
本文来说下Netty 是如何实现 TCP 心跳机制与断线重连的 文章目录 什么是心跳机制HeartBeat 如何实现心跳机制 Netty实现自定义的心跳机制 服务端 客户端 测试效果 客户端断线重连 ...
- Labview 编写TCP/IP 客户端断线重连机制程序,亲测可用
程序面板如下图: 此程序支持任意一方断线重连机制,仅供大家参考! 实际工程中,如果出现服务器出现宕机,那么我们的客户端要有重连的机制,不然软件不会自动连接服务器,明显是我们程序编写的一个漏洞,无论是从 ...
- Socket网络编程tcp聊天案例(心跳包,多线程,断线重连机制)
实现一个聊天的案例,使用多线程和心跳包.当服务器断开的时候,客户端会自动尝试重新连接,当服务器开启的时候,客户端会自动连接 Server服务器类 package Demo3_Chat;import c ...
- 面试官问:服务的心跳机制与断线重连,Netty底层是怎么实现的?懵了
点击上方蓝色"方志朋",选择"设为星标" 回复"666"获取独家整理的学习资料! 心跳机制 何为心跳 所谓心跳, 即在 TCP 长连接中, ...
- Netty实现心跳机制与断线重连
点击上方蓝色"方志朋",选择"设为星标" 回复"666"获取独家整理的学习资料! 来源:https://www.jianshu.com/p/ ...
- 浅析 Netty 实现心跳机制与断线重连
基础 何为心跳 顾名思义, 所谓 心跳, 即在 TCP 长连接中, 客户端和服务器之间定期发送的一种特殊的数据包, 通知对方自己还在线, 以确保 TCP 连接的有效性. 为什么需要心跳 因为网络的不可 ...
最新文章
- 网络钓鱼大讲堂 Part4 | 网络钓鱼攻击战术
- 一个Spring入门小案例
- Mininet 系列实验(一)
- jenkins学习笔记2-在centos中安装jenkins master测试环境
- 通宵爆肝:C语言下的平衡二叉树(Avl)原来如此简单!
- MiningZhiDaoQACorpus,580万百度知道问题,980万问答对数据挖掘项目
- 编程语言在中国哪种职位最多_您使用最多的是哪种“古老”编程语言?
- java override 用法_Java中@Override的作用
- 兰州职称计算机中心,【兰州2013年职称计算机考试报名通知】- 环球网校
- Zephyr学习(一)Zephyr介绍
- oracle数据库查询正在执行的sql,Oracle查询正在执行的SQL语句
- IOS 关于扬声器和听话筒的设置 ----自己试验过的,可以达到扩音器和听筒播放的效果...
- JavaScript的三种弹窗
- 最值得收藏的 搜狗输入法 常用快捷键使用, 让你的效率成倍增加
- 功不唐捐 玉汝于成---贪心算法终结
- 虚拟机虚拟磁盘文件格式转换
- 纵观 Excel 演化史,开发者如何通过“表格技术”提升企业生产力
- Jmeter接口测试+压力测试
- C++字符串的几种输入方法(string和字符数组)
- 大数据项目(BP神经网络)
热门文章
- 诺基亚n1 android 6.0,数据解读诺基亚N1:安卓平板王者之争
- Comet实现的新选择
- 上海2021年高考成绩排位查询,上海各区2021年一模成绩排位情况汇总!
- 手机上所部署的DigiCert证书过期怎么办
- Java CSS3:(七)CSS3 中常用的样式(跳动的心)
- Python 文件命名引发的module has no attribute错误
- 魔兽怀旧服一个服务器最多人数,魔兽怀旧服:比灰烬排队人数还多的服务器,仅此一个,过于平衡!...
- python从入门到放弃篇31(selenium库)模拟天猫登录输入不含验证码,初步实现
- 网络表示学习Network Representation Learning/Embedding
- pytorch--从零实现一个BERT模型