这段时间用STM32移植LwIP做语音传输。但是遇到一个问题困扰许久,在使用TCP方式做一个client去连接server,由于数据量比较大经常在连接一个多小时候就出现断线而
也ping不通。接下来我们看一下这个问题是怎么出现的和他的决绝方法(小白一枚,说错的地方还望指正哈 。。。。共同学习 。嘻嘻 ^_^ )。
额,还没有学操作系统,还生活在裸奔的年代。。。 client和server采用LwIP的Raw函数编写。连接过程采用短连接,即发送一次数据就请求断开。
我们先看一个client端的程序。
/**************************************/
以太网实验,步骤
///
1.把M3接入路由。
///
2.ping实验。在接入相同路由的PC中,运行CMD,输入命令: ping 192.168.1.18
看是否能ping通,只有ping通后才能进行后续的实验。
*********ping通的实验现象如下(时间可能稍有区别)***********
C:\Documents and Settings\>ping 192.168.1.18
Pinging 192.168.1.18 with 32 bytes of data:
Reply from 192.168.1.18: bytes=32 time=1ms TTL=255
Reply from 192.168.1.18: bytes=32 time=2ms TTL=255
Reply from 192.168.1.18: bytes=32 time<1ms TTL=255
Reply from 192.168.1.18: bytes=32 time=1ms TTL=255
Ping statistics for 192.168.1.18:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 2ms, Average = 1ms
******************************************************************
若不能ping通,可能是路由的限制:
可尝试把M3与PC直接用网线相连, 再 ping 192.168.1.18 ,
如果还不通,排除网线及接触问题后,可能是代码被修改或板子故障。
///
3.telnet实验。ping通后,输入命令: telnet 192.168.1.18
使用用户名:wildfire 密码:123456 登录。
登录成功后可选两条指令:LED1_ON 和 LED1_OFF 用于远程控制。
***************正常实验现象如下****************************************
屏幕输出 Please enter your username:
键盘输入 wildfire
屏幕输出 Please enter your password:
键盘输入 123456
屏幕输出 Please enter command:
键盘输入 LED1_ON
屏幕输出 Success,LED1 status is ON!
屏幕输出 Please enter command:
键盘输入 LED1_OFF
屏幕输出 Success,LED1 status is OFF!
屏幕输出 Please enter command:
************输入命令LED1_ON后,板上的LED1会点亮,输入LED1_OFF后,LED1熄灭****************
(win7系统没有telnet,需要在网上下载该程序进行实验)
////
4.浏览器实验。打开浏览器,在地址栏输入 http://192.168.1.18
连接成功后,可看到登录界面。输入:
*****************************************************
用户名:wildfire
密码 :123456
*****************************************************
登录成功后,可点击LED控制界面对M3板上的LED1进行控制。
(如果不是原版代码,该网页上的野火旗舰店网址链接可能会被恶意篡改。)
单片机源程序如下:
- /**
- ******************************************************************************
- * @file main.c
- * @author fire
- * @version V1.0
- * @date 2013-xx-xx
- * @brief enc28j60+lwip测试,具体测试步骤参考工程里面的文件readme.txt
- */
- /* Includes ------------------------------------------------------------------*/
- #include <stdio.h>
- #include "stm32f10x.h"
- #include "stm32f10x_usart.h"
- #include "err.h"
- #include "etharp.h"
-
- #include "netconfig.h"
- #include "bsp_usart1.h"
- #include "bsp_SysTick.h"
- #include "spi.h"
- #include "bsp_led.h"
- #include "cmd.h"
- #include "httpd.h"
- #include "DAC.h"
- #include "TIM2delay.h"
- #include "edcode.h"
- #include "ADPCM.h"
- #include "ADC.h"
- /*****************************************************************************************************************************/
- __IO uint32_t LocalTime = 0;
- /* this variable is used to create a time reference incremented by 10ms */
-
- /*
- * 函数名:main
- * 描述 :主函数
- * 输入 :无
- * 输出 : 无
- * 调用 :
- */
- int main(void)
- {
- /*初始化串口*/
- USART1_Config();
- /*初始化 以太网SPI接口*/
- ENC_SPI_Init();
- /*初始化systick,用于定时轮询输入或给LWIP提供定时*/
- SysTick_Init();
- ADC1_Init();//ADC 初始化 采用DMA方式
-
- printf("\r\n************************\r\n");
-
- /* 初始化LWIP协议栈*/
- LwIP_Init(); //192.168.1.18
- /*初始化web server 显示网页程序*/
- httpd_init();
- DAC_init(); //DAC初始化
-
-
- timer_init(32);//定时器初始化 开始播放
- /* Infinite loop */
- while ( 1 )
- {
- /*轮询*/
- LwIP_Periodic_Handle(LocalTime);
- decoding( ); //解码
-
- encoding( );
-
-
-
- }
- }
复制代码
所有资料51hei提供下载:
LwIP client server.7z
(630.54 KB, 下载次数: 60)
|