- void client_init(void)
- {
- struct udp_pcb *upcb;
- struct pbuf *p;
- SET_IP4_ADDR(&ip_udp_server, UDP_SERVER_IP);
- /* Create a new UDP control block */
- upcb = udp_new();
- p = pbuf_alloc(PBUF_TRANSPORT, sizeof(Sent), PBUF_RAM);
- p->payload = (void*)sm;
- p->len =8;
- p->tot_len = 8;
- upcb->local_port = UDP_CLIENT_PORT;
- /* Bind the upcb to any IP address and the UDP_PORT port*/
- udp_bind(upcb, IP_ADDR_ANY, UDP_CLIENT_PORT);
- udp_connect(upcb, &ip_udp_server, UDP_SERVER_PORT);
- udp_send(upcb, p);
- // udp_disconnect(upcb); //毙掉这里,pc端发送来的数据,无法接收,添加上这个语句则可以收到,为什么,求解释?
- udp_recv(upcb, udp_client_callback, NULL);
- /* Free the p buffer */
- pbuf_free(p);
-
- }
|