0.png (41.38 KB, 下載次數: 109)
下載附件
2018-12-11 22:12 上傳
這段時間用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)
2018-12-11 22:10 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|