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 连接的有效性. 为什么需要心跳 因为网络的不可 ...
最新文章
- 程序员:请你不要对业务「置之不理」
- 精品软件 推荐 瑞星 杀毒软件 安全软件
- (一)win7下cocos2d-x 21 + vs2010
- 搞事情?!2020云·创季来啦,量子位带你领略云产业的耳目一新!
- DNS服务器之简单配置(一)
- Remoting系列专题---自定义序列化类
- Vue-cli项目中路由的基础用法,以及路由嵌套
- mysql 转型_MySQL的未来在哪?
- Java数据类型分类
- 返回json格式的编写(Msg)
- 曾创下IRR62%的超高战绩的VC离开中国:一切因人而来因人而去
- ApacheCN Python 译文集 20211108 更新
- 2022数字化工地智慧防疫系统助力工地疫情防控实现人员、施工安全闭环管理
- 敏捷开发 敏捷个人_在敏捷2013中寻找答案
- 用Matlab将坐标添加到地图上
- VS2013使用教程总结(3)---修改VA的注释
- IAR配色方案及配置方法
- 将html字符串转换成html标签显示到页面上(转)
- RTSP协议网络摄像头如何实现内网到公网的无插件直播,同时支持微信扫码直播观看?
- 信息爆炸的时代怎样来读书
热门文章
- 留不住用户 FireFox中国市场占有率下跌8.6%
- 基于图像的三维建模——特征点检测与匹配
- 淘宝店小蜜配置手册——店小蜜收费策略及应对方案
- c语言字节的高地位互换,c语言面试题目100及最佳答案(51页)-原创力文档
- 【1.9w字】彻底搞懂HTTP知识的面试题,建议精读收藏
- 基于ThinkPHP框架开发的漂亮的家装修公司网站PHP源码
- 斯坦福ner python_斯坦福大学Corenlp和Java入门(Python程序员)
- charles 过期了怎么办
- h200和gr1108_华三H3C GR1108-P 路由器性能极限
- BZOJ1616[Usaco2008 Mar]Cow Travelling游荡的奶牛 dp