LwIP 的tcp_connect求救

[复制链接]
 楼主| can123dao 发表于 2013-8-1 15:39 | 显示全部楼层 |阅读模式
用STM32F103ZET6+ENC28J60+LWIP,将开发板和电路通过路由连到同一局域网内,成功实现了client,server功能,正常连接,通信正常,也无大家说了上线下线的现象。后面加上了DHCP功能,成功分配IP,server功能测试,正常;但,测试client功能时,无法连接成功。
发现tcp_connect(client_pcb, &destip, 4, tcp_client_connected);并不调用tcp_client_connected;不知道什么原因。有人能解答一下么。
一关闭DHCP就能用,但打开后,client就不行了,server能用。
  1. int main(void)
  2. {
  3.    sys_config();
  4.    SysTick_Init();       
  5.    LwIP_Init();

  6.    tcp_server_init();
  7.    tcp_client_init();


  8.    while(1)
  9.    {
  10.           
  11.                    LwIP_Periodic_Handle(LocalTime);       
  12.    }
  13. }

  14. void tcp_server_init(void)
  15. {
  16.         struct tcp_pcb *pcb;

  17.         printf("tcp server init\n");
  18.        
  19.         pcb = tcp_new();

  20.         tcp_bind(pcb, IP_ADDR_ANY, 1200);

  21.         pcb = tcp_listen(pcb);
  22.                                            
  23.     tcp_accept(pcb, tcp_server_accept);       
  24. }

  25. void tcp_client_init(void)
  26. {
  27.         struct tcp_pcb *client_pcb;
  28.         struct tcp_client_app_arg* app_arg;
  29.         static struct ip_addr destip;
  30.         printf("tcp client inti\n");

  31.         IP4_ADDR(&destip,192,168,0,105);

  32.         client_pcb = tcp_new();
  33.         tcp_bind(client_pcb,IP_ADDR_ANY,4);
  34.         if(client_pcb != NULL)
  35.         {
  36.                 tcp_arg(client_pcb, mem_calloc(sizeof(struct tcp_client_app_arg), 1));   
  37.                 app_arg = client_pcb->callback_arg;
  38.                 app_arg->app_state = CLIENT_WAITING_FOR_CONNECTION;       
  39.                 tcp_connect(client_pcb, &destip, 4, tcp_client_connected);         
  40.         }
  41.         else
  42.         {

  43.                 printf("tcp alloc failed\n");
  44.         }
  45. }

  46. err_t tcp_client_connected(void *arg, struct tcp_pcb *pcb, err_t err)
  47. {
  48.         struct tcp_client_app_arg *app_arg = (struct tcp_client_app_arg *)arg;
  49.         uint8_t* str = "Welcome to the client\n";
  50.        
  51.         printf("tcp client connected\n");

  52.         tcp_err(pcb, tcp_client_errf);                 //指定出错时的回调函数
  53.           tcp_recv(pcb, tcp_client_recv);                 //指定接收到新数据时的回调函数
  54.         tcp_sent(pcb, tcp_client_sent);                 //指定远程主机成功接收到数据的回调函数
  55.         tcp_poll(pcb, tcp_client_poll, 4);         //指定轮询的时间间隔和回调函数(*250ms)

  56.         tcp_write(pcb, (const char *)str, strlen(str), 1);
  57.         app_arg->app_state = CLIENT_WAITING_FOR_CMD;

  58.         return ERR_OK;
  59. }

         
 楼主| can123dao 发表于 2013-8-1 18:20 | 显示全部楼层
通过设置错误调用函数,发现是ERR_ABRT:Connection aborted
puchuang 发表于 2013-8-1 19:00 | 显示全部楼层
问题解决了就好  楼主  顶你
 楼主| can123dao 发表于 2013-8-1 19:02 | 显示全部楼层
puchuang 发表于 2013-8-1 19:00
问题解决了就好  楼主  顶你

么有解决,为什么会abort,
 楼主| can123dao 发表于 2013-8-7 11:47 | 显示全部楼层
结了吧,解决不来,好好学习
您需要登录后才可以回帖 登录 | 注册

本版积分规则

36

主题

114

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部

36

主题

114

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部