中级会员
- 积分
- 202
- 金钱
- 202
- 注册时间
- 2015-8-3
- 在线时间
- 45 小时
|
10金钱
##netconn_connect(conn_send, addr_local_send, port_send);在这个函数中无法指定远端的IP ,addr_local_send,请问这个 addr_local_send怎么赋值初始化?用这个IP4_ADDR(addr_local_send, 192, 168, 0, 123)无法初始化
##netconn_connect第二个参数怎么初始化?
//****代码如下****************************************
static void UdpSendData_thread(void *arg)
{
static struct netconn *conn_send;
static struct netbuf *buf_send;
static struct ip_addr *addr_local_send,*addr_me,*addr_lu;
static unsigned short port_send;
err_t err_0,recv_err;
TypedefStatusMsg StatusMsg;
BaseType_t xResult;
uint8_t *data_rec;
u16 len_rec;
LWIP_UNUSED_ARG(arg);
conn_send = netconn_new(NETCONN_UDP);//初始化创建UDP网络服务
if (conn_send!= NULL)
{
IP4_ADDR(addr_me, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);//本地IP
IP4_ADDR(addr_local_send, 192, 168, 0, 123);//发送对端IP
// printf("addr_me: %ld addr0: %ld \r\n",addr_me->addr,addr_local_send->addr);
err_0 = netconn_bind(conn_send, addr_me, 2883);//绑定 IP port :IP_ADDR_ANY时,则绑定到所有的本地IP地址
port_send = 2883;
if(err_0==ERR_OK)
{
while(1)
{
recv_err = netconn_recv(conn_send, &buf_send);//阻塞等待数据
if (recv_err == ERR_OK)
{
addr_lu = netbuf_fromaddr(buf_send);//读取对方地址 IP
port_send = netbuf_fromport(buf_send);//读取对方端口 port
netbuf_data(buf_send,(void **) &data_rec, &len_rec);
// addr_local_send->addr=addr_lu->addr ;
netconn_connect(conn_send, addr_local_send, port_send);
buf_send->addr.addr = 0;//发送原始对方数据
// netconn_sendto(conn_send,buf_send,addr_local_send,port_send);
netconn_send(conn_send,buf_send);
netbuf_delete(buf_send);
}
else
{
printf("udp-data time out \r\n");
}
//vTaskDelayUntil(&xLastWakeTime,100);
}
}
else
{
netconn_delete(conn_send);
printf(" 1 can not bind netconn");
}
}
else
{
printf("can create new UDP netconn");
}
}
|
|