|
UDP client 端能发送出去,但是无法接到数据(跳不到接受回调函数),,帮看看什么问题,各位????是神州的开发板源码,,不知道为什么无法接受到数据6 ]' ~/ |& e! W) c0 ?2 o #define UDP_SERVER_PORT 8006 #define UDP_CLIENT_PORT 46 e4 J) f- b* n: y #define TCP_PORT 45 S( s' c7 Z* r/ R) V #define UDP_CLIENT_IP 255,255,255,255 % H" C- y- f V& d5 l void client_init(void)5 C4 y- M! e0 X4 { {0 x0 }6 F; |9 a% A7 B# @ struct udp_pcb *upcb;) x( k2 x: y% s4 I. g" K+ j L7 l struct pbuf *p; 2 y& M' j6 P# V9 g6 G& J7 e /* Create a new UDP control block */# j* A0 |( l% d$ a upcb = udp_new(); * ]; P2 {/ `$ ^9 a; E( b SET_IP4_ADDR(&ip_udp_server,UDP_CLIENT_IP);6 g. P0 \0 T/ G! t& H0 e p = pbuf_alloc(PBUF_TRANSPORT, sizeof(Sent), PBUF_RAM);( ~+ K- b* e* x- _! U5 { p->payload = (void*)Sent; udp_bind(upcb, IP_ADDR_ANY, 4); udp_connect(upcb, &ip_udp_server, UDP_SERVER_PORT); ' M, C3 ]* S9 x udp_send(upcb, p); 7 Z! Y' v" q2 j [2 { udp_recv(upcb, udp_client_callback, NULL);' D# u% {8 q/ |, b, a9 {/ B# ~+ Y /* Free the p buffer */, m0 o" h; m1 Z' H; K0 I pbuf_free(p); } 5 Q: o6 L5 K& _# G void udp_client_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port)% P, d8 l3 X2 X: w" ` {- z K1 X9 B3 S( d& `1 q struct tcp_pcb *pcb; __IO uint8_t iptab[4];7 I8 ?+ U: K- J2 ] uint8_t iptxt[20]; /* Create a new TCP control block */ pcb = tcp_new();; j5 Y- s; J5 t; y+ [ 5 y# p5 g k4 y) B) \7 i+ |0 ` /* Assign to the new pcb a local IP address and a port number */: {1 @; ^" n& s tcp_bind(pcb, IP_ADDR_ANY, TCP_PORT);( @+ Q) z* Y% V /* Connect to the server: send the SYN */5 }7 r" X; ^, O% |& A) ~4 u tcp_connect(pcb, addr, TCP_PORT, tcp_client_connected);( m% C( a' S9 q) b. {2 X1 F- g /* Free the p buffer */! I' B0 F9 ~; l* U( C* R4 Q" y( I pbuf_free(p); } $ U7 }/ [3 r, ?0 L$ g |
udp server端
微信公众号
手机版
tcp_bind(pcb, IP_ADDR_ANY, TCP_PORT);你是不是指,绑定的本地IP_ADDR_SNY地址有问题?