Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
Network
lwip1.4.1连接经常会断开无法连接上,可以ping通
发布于 2014-11-13 08:23:40 浏览:12322
订阅该版
描述:改自realtouch的代码,用作服务器端,使用tcpip通信,上位机连接一段时间后,会自动断开,无法收发数据,上位机报错the network connection was closed by the peer,下位机报错-12或者-13,此时可以ping通。这是什么原因? 服务器端代码如下: ``` static void tcpserv_thread_entry(void* parameter) { char *recv_data_buf,*send_data_buf; // rt_uint32_t sin_size; int sock, connected; struct sockaddr_in server_addr, client_addr; rt_uint16_t received_len,send_len; recv_data_buf = (char *)rt_malloc(RECV_BUF_SIZE); // send_data_buf = (char *)rt_malloc(SEND_BUF_SIZE); if (NULL == recv_data_buf || NULL == send_data_buf) { rt_kprintf("No memory "); goto TCP_SERVER_QUIT; } rt_memset(recv_data_buf,0x0,RECV_BUF_SIZE); rt_memset(send_data_buf,0x0,SEND_BUF_SIZE); // if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { // rt_kprintf("Socket error "); goto TCP_SERVER_QUIT; } // server_addr.sin_family = AF_INET; server_addr.sin_port = htons(SERVER_PORT); // server_addr.sin_addr.s_addr = INADDR_ANY; rt_memset(&(server_addr.sin_zero),8, sizeof(server_addr.sin_zero)); // if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) { // rt_kprintf("Unable to bind "); goto TCP_SERVER_QUIT; } // if (listen(sock, 5) == -1) { rt_kprintf("Listen error "); goto TCP_SERVER_QUIT; } rt_kprintf("TCPServer Waiting for client on port %d... ",SERVER_PORT); sin_size = sizeof(struct sockaddr_in); while(1) { // connected = accept(sock, (struct sockaddr *)&client_addr, &sin_size); // received_len = recv(connected,recv_data_buf, RECV_BUF_SIZE, 0); if (received_len > 0) { //ATE_LinkComing(ATE_LINK_ETH); //recv_data_buf[received_len] = ' '; TCP_data_process(recv_data_buf,received_len,send_data_buf,&send_len); //rt_uint16_t temp = SHORT_little_endian_TO_big_endian(send_len); send(connected, &send_len, sizeof(send_len), 0); // send(connected, send_data_buf, send_len, 0);// //rt_memset(send_data_buf,0x0,send_len); } /* 关闭这个connected socket */ lwip_close(connected); } TCP_SERVER_QUIT: rt_kprintf("error,TCP Server quit "); // lwip_close(sock); // rt_free(recv_data_buf); rt_free(send_data_buf); RT_ASSERT(0); return ; } ``` 无法连接后,lwip的log就停住了 lwip_accept(0)... lwip_accept(0) returning new sock=1 addr=192.168.1.20 port=48014 lwip_recvfrom(1, 20011170, 2048, 0x0, ..) lwip_recvfrom: top while sock->lastdata=00000000 lwip_recvfrom: netconn_recv err=0, netbuf=200178b0 lwip_recvfrom: buflen=8 len=2048 off=0 sock->lastoffset=0 lwip_recvfrom(1): addr=192.168.1.20 port=48014 len=8 lwip_recvfrom: deleting netbuf=200178b0 lwip_send(1, data=2000e290, size=2, flags=0x0) lwip_send(1) err=0 written=2 lwip_send(1, data=2001197c, size=8, flags=0x0) lwip_send(1) err=0 written=8 lwip_close(1) lwip_accept(0)... lwip_accept(0) returning new sock=1 addr=192.168.1.20 port=48015 lwip_recvfrom(1, 20011170, 2048, 0x0, ..) lwip_recvfrom: top while sock->lastdata=00000000 lwip_recvfrom: netconn_recv err=0, netbuf=200178b0 lwip_recvfrom: buflen=8 len=2048 off=0 sock->lastoffset=0 lwip_recvfrom(1): addr=192.168.1.20 port=48015 len=8 lwip_recvfrom: deleting netbuf=200178b0 lwip_send(1, data=2000e290, size=2, flags=0x0) lwip_send(1) err=0 written=2 lwip_send(1, data=2001197c, size=8, flags=0x0) lwip_send(1) err=0 written=8 lwip_close(1) lwip_accept(0)... lwip_accept(0) returning new sock=1 addr=192.168.1.20 port=47757 lwip_recvfrom(1, 20011170, 2048, 0x0, ..) lwip_recvfrom: top while sock->lastdata=00000000 lwip_recvfrom: netconn_recv err=-12, netbuf=00000000 lwip_recvfrom(1): buf == NULL, error is "Connection closed."! lwip_close(1) lwip_accept(0)... lwip_accept(0) returning new sock=1 addr=192.168.1.20 port=47758 lwip_recvfrom(1, 20011170, 2048, 0x0, ..) lwip_recvfrom: top while sock->lastdata=00000000 lwip_recvfrom: netconn_recv err=-12, netbuf=00000000 lwip_recvfrom(1): buf == NULL, error is "Connection closed."! lwip_close(1) lwip_accept(0)... lwip_accept(0) returning new sock=1 addr=192.168.1.20 port=47759 lwip_recvfrom(1, 20011170, 2048, 0x0, ..) lwip_recvfrom: top while sock->lastdata=00000000 lwip_recvfrom: netconn_recv err=-12, netbuf=00000000 lwip_recvfrom(1): buf == NULL, error is "Connection closed."! lwip_close(1) lwip_accept(0)... lwip_accept(0) returning new sock=1 addr=192.168.1.20 port=48017 lwip_recvfrom(1, 20011170, 2048, 0x0, ..) lwip_recvfrom: top while sock->lastdata=00000000 lwip_recvfrom: netconn_recv err=0, netbuf=200178b0 lwip_recvfrom: buflen=8 len=2048 off=0 sock->lastoffset=0 lwip_recvfrom(1): addr=192.168.1.20 port=48017 len=8 lwip_recvfrom: deleting netbuf=200178b0 lwip_send(1, data=2000e290, size=2, flags=0x0) lwip_send(1) err=0 written=2 lwip_send(1, data=2001197c, size=8, flags=0x0) lwip_send(1) err=0 written=8 lwip_close(1) lwip_accept(0)... lwip_accept(0) returning new sock=1 addr=192.168.1.20 port=47760 lwip_recvfrom(1, 20011170, 2048, 0x0, ..) lwip_recvfrom: top while sock->lastdata=00000000 finsh /> finsh /> finsh /> 此时,ping是正常的 ![1.JPG](/uploads/6263_90d273a97373587d6fe375a9aa2d7d5b.jpg)
查看更多
8
个回答
默认排序
按发布时间排序
cris8259
2014-11-13
这家伙很懒,什么也没写!
log2: ``` lwip_accept(0)... lwip_accept(0) returning new sock=1 addr=192.168.1.20 port=43217 lwip_recvfrom(1, 20011170, 2048, 0x0, ..) lwip_recvfrom: top while sock->lastdata=00000000 lwip_recvfrom: netconn_recv err=0, netbuf=200178b0 lwip_recvfrom: buflen=8 len=2048 off=0 sock->lastoffset=0 lwip_recvfrom(1): addr=192.168.1.20 port=43217 len=8 lwip_recvfrom: deleting netbuf=200178b0 lwip_send(1, data=2000e290, size=2, flags=0x0) lwip_send(1) err=0 written=2 lwip_send(1, data=2001197c, size=8, flags=0x0) lwip_send(1) err=0 written=8 lwip_close(1) lwip_accept(0)... lwip_accept(0) returning new sock=1 addr=192.168.1.20 port=43120 lwip_recvfrom(1, 20011170, 2048, 0x0, ..) lwip_recvfrom: top while sock->lastdata=00000000 lwip_recvfrom: netconn_recv err=-12, netbuf=00000000 lwip_recvfrom(1): buf == NULL, error is "Connection closed."! lwip_close(1) lwip_accept(0)... lwip_accept(0) returning new sock=1 addr=192.168.1.20 port=43121 lwip_recvfrom(1, 20011170, 2048, 0x0, ..) lwip_recvfrom: top while sock->lastdata=00000000 lwip_recvfrom: netconn_recv err=-12, netbuf=00000000 lwip_recvfrom(1): buf == NULL, error is "Connection closed."! lwip_close(1) lwip_accept(0)... lwip_accept(0) returning new sock=1 addr=192.168.1.20 port=43122 lwip_recvfrom(1, 20011170, 2048, 0x0, ..) lwip_recvfrom: top while sock->lastdata=00000000 lwip_recvfrom: netconn_recv err=-12, netbuf=00000000 lwip_recvfrom(1): buf == NULL, error is "Connection closed."! lwip_close(1) lwip_accept(0)... lwip_accept(0) returning new sock=1 addr=192.168.1.20 port=43219 lwip_recvfrom(1, 20011170, 2048, 0x0, ..) lwip_recvfrom: top while sock->lastdata=00000000 lwip_recvfrom: netconn_recv err=0, netbuf=200178b0 lwip_recvfrom: buflen=8 len=2048 off=0 sock->lastoffset=0 lwip_recvfrom(1): addr=192.168.1.20 port=43219 len=8 lwip_recvfrom: deleting netbuf=200178b0 lwip_send(1, data=2000e290, size=2, flags=0x0) lwip_send(1) err=0 written=2 lwip_send(1, data=2001197c, size=8, flags=0x0) lwip_send(1) err=0 written=8 lwip_close(1) lwip_accept(0)... lwip_accept(0): netconn_peer failed, err=-13 lwip_recvfrom(-1, 20011170, 2048, 0x0, ..) get_socket(-1): invalid lwip_send(-1, data=2000e290, size=2, flags=0x0) get_socket(-1): invalid lwip_send(-1, data=2001197c, size=8, flags=0x0) get_socket(-1): invalid lwip_close(-1) get_socket(-1): invalid lwip_accept(0)... lwip_accept(0) returning new sock=1 addr=192.168.1.20 port=43124 lwip_recvfrom(1, 20011170, 2048, 0x0, ..) lwip_recvfrom: top while sock->lastdata=00000000 finsh /> finsh /> ```
pangwei
2014-11-14
这家伙很懒,什么也没写!
received_len =0后会怎么样,分析下程序逻辑。
cris8259
2014-11-14
这家伙很懒,什么也没写!
如果把下位机lwip的log打开,更容易出现这个现象,像是下位机反应比较慢,上位机连接频繁的时候,更容易出现。不知道下位机发送的过程中,上位机断掉连接会怎么样?好像是上位机提前断掉连接造成的
cris8259
2014-11-14
这家伙很懒,什么也没写!
``` finsh />list_tcps() Active PCB states: #0 192.168.1.30:8259 <==> 192.168.1.20:9478 snd_nxt 0x00001996 rcv_nxt 0x91CF872A state: ESTABLISHED #1 192.168.1.30:8259 <==> 192.168.1.20:9425 snd_nxt 0x00001991 rcv_nxt 0xD4BF749B state: ESTABLISHED #2 192.168.1.30:8259 <==> 192.168.1.20:9424 snd_nxt 0x00001990 rcv_nxt 0x18D0CA05 state: ESTABLISHED Listen PCB states: #0 local port 8259 state: LISTEN #1 local port 8258 state: LISTEN TIME-WAIT PCB states: #0 192.168.1.30:8259 <==> 192.168.1.20:9476 snd_nxt 0x00001ACE rcv_nxt 0x587BF184 state: TIME_WAIT #1 192.168.1.30:8259 <==> 192.168.1.20:9474 snd_nxt 0x00001AC9 rcv_nxt 0xF8DA7249 state: TIME_WAIT #2 192.168.1.30:8259 <==> 192.168.1.20:9472 snd_nxt 0x00001AC4 rcv_nxt 0xE6C2E03B state: TIME_WAIT #3 192.168.1.30:8259 <==> 192.168.1.20:9470 snd_nxt 0x00001ABF rcv_nxt 0xA72865F4 state: TIME_WAIT #4 192.168.1.30:8259 <==> 192.168.1.20:9469 snd_nxt 0x00001ABD rcv_nxt 0x77A2AC4B state: TIME_WAIT #5 192.168.1.30:8259 <==> 192.168.1.20:9468 snd_nxt 0x00001ABC rcv_nxt 0x725C3CE9 state: TIME_WAIT #6 192.168.1.30:8259 <==> 192.168.1.20:9467 snd_nxt 0x00001ABB rcv_nxt 0x336F4EE0 state: TIME_WAIT #7 192.168.1.30:8259 <==> 192.168.1.20:9466 snd_nxt 0x00001ABA rcv_nxt 0xB844F9AA state: TIME_WAIT #8 192.168.1.30:8259 <==> 192.168.1.20:9465 snd_nxt 0x00001AB9 rcv_nxt 0x22C1365B state: TIME_WAIT #9 192.168.1.30:8259 <==> 192.168.1.20:9464 snd_nxt 0x00001AB8 rcv_nxt 0x4FD807FD state: TIME_WAIT #10 192.168.1.30:8259 <==> 192.168.1.20:9463 snd_nxt 0x00001AB7 rcv_nxt 0xF7C5DC7E state: TIME_WAIT #11 192.168.1.30:8259 <==> 192.168.1.20:9462 snd_nxt 0x00001AB6 rcv_nxt 0x967F9497 state: TIME_WAIT #12 192.168.1.30:8259 <==> 192.168.1.20:9461 snd_nxt 0x00001AB5 rcv_nxt 0xFB08EDBB state: TIME_WAIT #13 192.168.1.30:8259 <==> 192.168.1.20:9460 snd_nxt 0x00001AB4 rcv_nxt 0x7BAE068E state: TIME_WAIT #14 192.168.1.30:8259 <==> 192.168.1.20:9459 snd_nxt 0x00001AB3 rcv_nxt 0xF957ACD1 state: TIME_WAIT #15 192.168.1.30:8259 <==> 192.168.1.20:9458 snd_nxt 0x00001AB2 rcv_nxt 0x6F136874 state: TIME_WAIT #16 192.168.1.30:8259 <==> 192.168.1.20:9457 snd_nxt 0x00001AB1 rcv_nxt 0x801398C5 state: TIME_WAIT #17 192.168.1.30:8259 <==> 192.168.1.20:9456 snd_nxt 0x00001AB0 rcv_nxt 0xE35FF6AD state: TIME_WAIT #18 192.168.1.30:8259 <==> 192.168.1.20:9455 snd_nxt 0x00001AAF rcv_nxt 0x353D635B state: TIME_WAIT #19 192.168.1.30:8259 <==> 192.168.1.20:9454 snd_nxt 0x00001AAE rcv_nxt 0x8EA1F9D4 state: TIME_WAIT #20 192.168.1.30:8259 <==> 192.168.1.20:9453 snd_nxt 0x00001AAE rcv_nxt 0x3C005A71 state: TIME_WAIT #21 192.168.1.30:8259 <==> 192.168.1.20:9452 snd_nxt 0x00001AAE rcv_nxt 0xFBC2A967 state: TIME_WAIT #22 192.168.1.30:8259 <==> 192.168.1.20:9451 snd_nxt 0x00001AAE rcv_nxt 0xEC83FD22 state: TIME_WAIT #23 192.168.1.30:8259 <==> 192.168.1.20:9449 snd_nxt 0x00001AAE rcv_nxt 0xDE5D53D8 state: TIME_WAIT #24 192.168.1.30:8259 <==> 192.168.1.20:9448 snd_nxt 0x00001AAE rcv_nxt 0xCD98303F state: TIME_WAIT #25 192.168.1.30:8259 <==> 192.168.1.20:9447 snd_nxt 0x00001AAE rcv_nxt 0x8E43C3DD state: TIME_WAIT #26 192.168.1.30:8259 <==> 192.168.1.20:9446 snd_nxt 0x00001AAE rcv_nxt 0xBBCF57CC state: TIME_WAIT #27 192.168.1.30:8259 <==> 192.168.1.20:9445 snd_nxt 0x00001AAE rcv_nxt 0x8E183D2C state: TIME_WAIT #28 192.168.1.30:8259 <==> 192.168.1.20:9444 snd_nxt 0x00001AAE rcv_nxt 0x7DFAD1DD state: TIME_WAIT #29 192.168.1.30:8259 <==> 192.168.1.20:9443 snd_nxt 0x00001AAE rcv_nxt 0xA7089B8F state: TIME_WAIT #30 192.168.1.30:8259 <==> 192.168.1.20:9442 snd_nxt 0x00001AAE rcv_nxt 0x441EC083 state: TIME_WAIT #31 192.168.1.30:8259 <==> 192.168.1.20:9441 snd_nxt 0x00001AAE rcv_nxt 0x51ACFC8F state: TIME_WAIT #32 192.168.1.30:8259 <==> 192.168.1.20:9440 snd_nxt 0x00001AAE rcv_nxt 0x590B31E9 state: TIME_WAIT #33 192.168.1.30:8259 <==> 192.168.1.20:9439 snd_nxt 0x00001AAE rcv_nxt 0xE475F1D2 state: TIME_WAIT #34 192.168.1.30:8259 <==> 192.168.1.20:9438 snd_nxt 0x00001AAE rcv_nxt 0x3C4A763E state: TIME_WAIT #35 192.168.1.30:8259 <==> 192.168.1.20:9437 snd_nxt 0x00001AAE rcv_nxt 0x294EAAA5 state: TIME_WAIT 0, 0x00000000 ```
cris8259
2014-11-14
这家伙很懒,什么也没写!
无法连接时出现多个time_wait
bernard
2014-11-14
这家伙很懒,什么也没写!
lwIP这边不要使用RT的内存管理,不打补丁会造成多个TIME_WAIT状态的TCP连接。
cris8259
2014-11-14
这家伙很懒,什么也没写!
没有打开宏RT_LWIP_USING_RT_MEM。不打补丁是什么意思?问题大概出在哪里?之前没出现过?
撰写答案
登录
注册新账号
关注者
0
被浏览
12.3k
关于作者
cris8259
这家伙很懒,什么也没写!
提问
25
回答
21
被采纳
0
关注TA
发私信
相关问题
1
LPC1768:RTT+LWIP+webserver用IE刷网页出现硬件中断错误(已经解决)
2
求一些LWIP开发的经验,目前ping一直不稳定。
3
stm32f207+dp83848无法ping通
4
RTT下的LWIP传递机制
5
rtt内lwip的socket是否是线程安全?
6
Lwip+enc28j60无法ping通
7
坑爹的rtconfig.h lwip关掉了checksum
8
花了一个晚上,把RT2.0的LWIP、网卡驱动、文件系统整合起来了,发现一点小问题
9
lwip例程中udp发送时如何指定源端口发送到指定目的地端口
10
【已解决】CME-M7芯片RTT+LWIP求助[遗留一个8小时固定死机问题]
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
使用百度AI助手辅助编写一个rt-thread下的ONVIF设备发现功能的功能代码
2
RT-Thread 发布 EtherKit开源以太网硬件!
3
rt-thread使用cherryusb实现虚拟串口
4
《C++20 图形界面程序:速度与渲染效率的双重优化秘籍》
5
《原子操作:程序世界里的“最小魔法单位”解析》
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
ota在线升级
UART
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
keil_MDK
rt_mq_消息队列_msg_queue
at_device
ulog
C++_cpp
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
张世争
8
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
11
个答案
1
次被采纳
KunYi
6
个答案
1
次被采纳
本月文章贡献
程序员阿伟
6
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
大龄码农
1
篇文章
2
次点赞
ThinkCode
1
篇文章
1
次点赞
Betrayer
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部