大佬们,小弟最近用ucos ii + lwip做tcp server。现在只是做一个简单的回传实验,一共两个任务,一个收一个发的,收的任务收到数据之后拷贝到发送buffer,给发的任务发一个信号,发的任务把收到的再发回去。但是一直死在netconn_accept里面。err一直是-3,也就是连接超时,调试软件那边连接的时候也显示1035 未知错误,有大佬遇到过这种情况么,小弟lwip新手,刚开始接触这个。板子是可以ping通的,代码里面还有一个udp收发的,是可以运行的,所以硬件应该是没什么问题的,下面是我的tcp server收发部分的代码: - <div style="text-align: left;"><p style="line-height: 30px; text-indent: 2em;"></p><div class="blockcode"><blockquote><div>void taskTcpServerRecv(void *data)</div><div>{</div><div>err_t err;</div><div>OS_CPU_SR cpu_sr;</div><div>uint32_t dataCount = 0;</div> <div>
- </div><div>newTcpServerDataReceivedSem = OSSemCreate(0);</div><div>OSEventNameSet(newTcpServerDataReceivedSem,"TcpServerDataReady",(INT8U *)&err);</div><div>struct netbuf *recvBuff;</div><div>tcpServerConn = netconn_new(NETCONN_TCP);</div><div>if(tcpServerConn)</div><div>{</div><div>err = netconn_bind(tcpServerConn,IP_ADDR_ANY,8088);</div><div>err = netconn_listen(tcpServerConn); </div><div>tcpServerConn->recv_timeout = 500;</div><div>for(;;)</div><div>{</div><div>err = netconn_accept(tcpServerConn,&newTcpServerConn);</div><div>if(err == ERR_OK)</div><div>{</div><div>newTcpServerConn->recv_timeout = 10;</div><div>for(;;)</div><div>{</div><div>err = netconn_recv(newTcpServerConn,&recvBuff);</div><div>if((err == ERR_OK) && (recvBuff != NULL))</div><div>{ </div><div>OS_ENTER_CRITICAL();</div><div>memset(TCPServerBuff.rxBuffer,0,TCPServerBuff.rxBufferSize);</div><div>for(struct pbuf *q = recvBuff->p;q != NULL;q = q->next)</div><div>{</div><div>if(q->len > (TCPServerBuff.rxBufferSize - dataCount)) </div><div>memcpy(TCPServerBuff.rxBuffer + dataCount,q->payload,(TCPServerBuff.rxBufferSize - dataCount));</div><div>else </div><div>memcpy(TCPServerBuff.rxBuffer + dataCount,q->payload,q->len);</div><div>dataCount += q->len; </div><div>if(dataCount > TCPServerBuff.rxBufferSize) </div><div>break;</div><div>}</div><div>OS_EXIT_CRITICAL();</div><div>TCPServerBuff.rxCount = dataCount;</div><div>dataCount=0;</div><div>netbuf_delete(recvBuff);</div><div>OSSemPost(newTcpServerDataReceivedSem);</div><div>}</div><div>else if(err == ERR_CLSD)</div><div>{</div><div>netconn_close(newTcpServerConn);</div><div>netconn_delete(newTcpServerConn);</div><div>break;</div><div>}</div><div>OSTimeDlyHMSM (0,0,0,10);</div><div>}</div><div>}</div><div>GPIOE->ODR ^= GPIO_Pin_15;</div><div>OSTimeDlyHMSM (0,0,0,500);</div><div>}</div><div>}</div><div>else</div><div>{</div><div>for(;;)</div><div>{</div><div>OSTimeDlyHMSM (0,0,0,10);</div><div>}</div><div>}</div><div>}</div><div>
- </div><div>
- </div><div>void taskTcpServerSend(void *data)</div><div>{</div><div>INT8U err;</div><div>for(;;)</div><div>{</div><div>OSSemPend(newTcpServerDataReceivedSem,0,&err);</div><div>memcpy((uint8_t *)TCPServerBuff.txBuffer,(uint8_t *)(TCPServerBuff.rxBuffer),TCPServerBuff.rxCount);</div><div>err = netconn_write(newTcpServerConn,(uint8_t *)TCPServerBuff.txBuffer,TCPServerBuff.rxCount, NETCONN_COPY);</div><div>TCPServerBuff.rxCount = 0;</div><div>OSTimeDlyHMSM (0,0,0,10);</div><div>}</div><div>}</div><div>
- </div><div>
- </div>
复制代码
|
这也建了两个任务,ucosii+lwip,一个用来发送camera数据,作server,另一个接收客户端发来的消息,可以看看有没有什么灵感。
评分
查看全部评分
基本上一样的操作啊。。。。都是new,bind,listen,accept。。。
评分
查看全部评分
评分
查看全部评分