最近需要用到网络
通信功能,就参考官方固件库里的参考应用样例 LwIP_HTTP_Server_Netconn_RTOS 这个工程
在此基础上粗暴的修改了一下改成了tcp client连接主机模式的了,但是并未成功,这个例程原本是一个基于tcp连接的一个http服务器,然后我改了里面的http_server_netconn_thread函数
参考f7教程里的tcp客户端例程修改了,发现一只卡在netconn_connect这里,也就是连接不上目标主机,我查了err值,对应的是
/** Rou
ting problem. */
ERR_RTE = -4
这个路由错误,但是我直接测试例程的时候是执行成功的也就是说物理线路接连和路由器没毛病,搞不懂了,请会的解答一下谢谢。
[C]
纯文本查看 复制代码
static void http_server_netconn_thread(void *arg){ static ip_addr_t server_addr;server_addr.addr = 0xc0a8c7bb; while(1){/* Create a new TCP connection handle */conn = netconn_new(NETCONN_TCP);LCD_UsrLog (" netconn_new ...n");/*netconn_bind(conn,NULL,7000);LCD_UsrLog (" netconn_bind ...n");*/err = netconn_connect(conn,&server_addr,8060);LCD_UsrLog (" netconn_connect ...n");if(err != ERR_OK) netconn_delete(conn);else if(err == ERR_OK){struct netbuf *recvbuf;while(1){netconn_write(conn,tcp_client_sendbuf,strlen(tcp_client_sendbuf),NETCONN_COPY);}}} /*if (conn!= NULL) { //-Bind to port 80 (HTTP) with default IP address err = netconn_bind(conn, NULL, 80); LCD_UsrLog (" netconn_bind ...n"); if (err == ERR_OK) { //-Put the connection into LISTEN state netconn_listen(conn);LCD_UsrLog (" netconn_listen ...n"); while(1) { //-accept any icoming connection accept_err = netconn_accept(conn, &newconn); if(accept_err == ERR_OK) { //-serve connection http_server_serve(newconn); //-delete connection netconn_delete(newconn); } } } }*/}