我用了楼主的tcp例子,在接收的函数里加了把收到的数据再发送回去的语句,与ZLG提供的“TCP&UDP测试工具”通讯。,开发板做服务器,“TCP&UDP测试工具”做客户端用发送间隔300ms的速度给开发板发数据,开发板接到数据后,把原数据返回给客户端。发现运行不到10分钟,就不通讯了,开发板无反应,连接不上,但能PING的通。试了几次都这样。这是什么原因呢?是不是程序里还需要加些什么措施?怎样才算通讯稳定呢?
修改的函数如下:
static err_t
APP_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
unsigned int i;
char *q;
struct pbuf *pcopy=p;
tAPPState *pState;
pState = arg;
if((err == ERR_OK) && (p != NULL))
{
tcp_recved(pcb, p->tot_len);
if(strncmp(p->payload, "LED ON", 6) == 0)
{
GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_4, GPIO_PIN_4);
//pbuf_free(p);
//tcp_sent(pcb, App_sent);
}
if(strncmp(p->payload, "LED OFF", 7) == 0)
{
GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_4, 0);
//pbuf_free(p);
//tcp_sent(pcb, App_sent);
}
//处理接收部分 while(pcopy)
{
tcp_write(pcb,pcopy->payload,pcopy->len,TCP_WRITE_FLAG_COPY);
pcopy=pcopy->next;
}
。
//发送数据
// send_data();
pbuf_free(p);
pbuf_free(pcopy);
}
if((err == ERR_OK) && (p == NULL))
{
//
// Close the connection.
//
tcp_arg(pcb, NULL);
tcp_sent(pcb, NULL);
tcp_recv(pcb, NULL);
mem_free(pState);
tcp_close(pcb);
}
return ERR_OK;
}
请高手解答一下,谢谢
[ 本帖最后由 boyong 于 2011-9-8 08:44 编辑 ]