中级会员
- 积分
- 380
- 金钱
- 380
- 注册时间
- 2013-6-27
- 在线时间
- 17 小时
|
楼主 |
发表于 2013-7-25 18:28:00
|
显示全部楼层
回复【4楼】styleno1:
---------------------------------
那我用了DHCP,下面的部分都要把tcp的改成udp咯。
void tcp_client_init(void)
{
struct tcp_pcb* client_pcb;
struct tcp_client_app_arg* app_arg;
printf("tcp client inti\n");
destip.addr = (uint32_t)192+(168<<8)+(0<<16)+(105<<24);
client_pcb = tcp_new();
if(client_pcb != NULL)
{
tcp_arg(client_pcb, mem_calloc(sizeof(struct tcp_client_app_arg), 1));
app_arg = client_pcb->callback_arg;
app_arg->app_state = CLIENT_WAITING_FOR_CONNECTION;
tcp_connect(client_pcb, &destip, 2200, tcp_client_connected);
}
else
{
printf("tcp alloc failed\n");
}
}
可是我又在107的例程里看到了这样东西 ,又作何解呢
void client_init(void)
{
struct udp_pcb *upcb;
struct pbuf *p;
upcb = udp_new();
udp_connect(upcb, IP_ADDR_BROADCAST, UDP_SERVER_PORT);
p = pbuf_alloc(PBUF_TRANSPORT, 0, BUF_RAM);
udp_send(upcb, p);
udp_disconnect(upcb);
udp_bind(upcb, IP_ADDR_ANY, UDP_CLIENT_PORT);
udp_recv(upcb, udp_client_callback, NULL);
/* Free the p buffer */
pbuf_free(p);
}
void udp_client_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
{
struct tcp_pcb *pcb;
__IO uint8_t iptab[4];
uint8_t iptxt[20];
/* Read the Server's IP address */
iptab[0] = (uint8_t)((uint32_t)(addr->addr) >> 24);
iptab[1] = (uint8_t)((uint32_t)(addr->addr) >> 16);
iptab[2] = (uint8_t)((uint32_t)(addr->addr) >> 8);
iptab[3] = (uint8_t)((uint32_t)(addr->addr));
sprintf((char*)iptxt, "is: %d.%d.%d.%d ", iptab[3], iptab[2], iptab[1], iptab[0]);
LCD_DisplayStringLine(Line3, "The server's IP add.");
LCD_DisplayStringLine(Line4, iptxt);
pcb = tcp_new();
tcp_bind(pcb, IP_ADDR_ANY, TCP_PORT);
tcp_connect(pcb, addr, TCP_PORT, tcp_client_connected);
pbuf_free(p);
} |
|