ucos+lwip中的关于netconn接口UDP通信问题请教
问大家一个问题,下面是我ucos+lwip中的关于netconn接口UDP通信,先能接收到数据,一发送数据就死机。找了两天都没有找到问题,郁闷。TCP通信都是没有问题的。{
static struct netconn *conn;
static struct netbuf*UDPNetbuf;
static struct ip_addr *addr;
static unsigned short port;
unsigned char Array;
int DataLen,i;
conn = netconn_new(NETCONN_UDP); /* 创建UDP连接*/
netconn_bind(conn, NULL,23);
while(1)
{
UDPNetbuf = netconn_recv(conn); //接受数据
addr = netbuf_fromaddr(UDPNetbuf);
port = netbuf_fromport(UDPNetbuf);
netconn_connect(conn, addr, port);
netconn_send(conn, UDPNetbuf);
netbuf_delete(UDPNetbuf);
}
} 还是我自己来。问题得到解决:
{
static struct netconn *conn;
static struct netbuf*UDPNetbuf;
static struct ip_addr *addr;
static struct ip_addr destip;
static unsigned short port;
unsigned char Array;
char *pTemp;
int DataLen;
conn = netconn_new(NETCONN_UDP); /* 创建UDP连接*/
netconn_bind(conn, IP_ADDR_ANY, 23);
while(1)
{
UDPNetbuf = netconn_recv(conn); //接受数据
addr = netbuf_fromaddr(UDPNetbuf);
port = netbuf_fromport(UDPNetbuf);
destip = *addr;
netconn_connect(conn, &destip, port);
netbuf_copy(UDPNetbuf, Array, UDPNetbuf->p->tot_len);
Array = '\0';
UDPNetbuf->addr=&destip;
UDPNetbuf->port=port;
netconn_send(conn, UDPNetbuf);
netbuf_delete(UDPNetbuf);
}
} 我也犯过同样的错误,不能直接转发。。。 楼主,你的是什么版本啊....我也调了n天..就是发送数据死机..我的是1.2.0版本..你的TCP通信可以贴出来看看不?谢谢你了. 回复【3楼】zhoudandandan 豆豆幻想
-----------------------------------------------------------------------
我这个是UDP,TCP是类似。 这个是TCP的
{
struct netconn *conn, *newconn = NULL;
struct netbuf *TCPNetbuf;
UARTprintf("TCP_Test_task\n");
conn = netconn_new(NETCONN_TCP); /* 创建TCP连接*/
netconn_bind(conn,NULL,80); /* 绑定本地地址和监听的端口号 */
netconn_listen(conn); /* 进入监听状态 */
while(1)
{
newconn = netconn_accept(conn); /*阻塞当前进程到有数据接收 */
if(newconn != NULL)
{
if((TCPNetbuf = netconn_recv(newconn)) != NULL)
{
netconn_write(newconn,(void *)http_html_hdr,sizeof(http_html_hdr),NETCONN_NOCOPY);
/* 发送头部数据*/
netconn_write(newconn,(void *)indexdata,sizeof(indexdata),NETCONN_NOCOPY);
/* 发送实际的WEB页面 */
netbuf_delete(TCPNetbuf);
}
netconn_close(newconn); /* 关闭连接 */
while(netconn_delete(newconn) != ERR_OK)
OSTimeDlyHMSM(0, 0, 1, 0);
}
}
} 我的也是UDP不通 markmark 强烈请求楼主开源{:dizzy:} 楼主udp怎么搞定的啊{:dizzy:}
页:
[1]