uip_listen() function not waiting to listen for connections - uIP library

拥有回忆 提交于 2019-12-12 04:13:09

问题


I am currently developping an application that performs a TCP/IP communication between an atmel AT91SAM7x256 microcontroller, and my Windows machine.

I have successfully compiled and linked the uIP standard library to my application. The uIP functions are getting recognized by the application, but the first thing I do in the main, for the application to listen to a connection request on port 51719 is:

#include <stdio.h>
#include "uip.h"
#define UIP_APPCALL client_app

int main(void) 
{
  printf("Hello World ");

  uip_init();

  printf("Establishing connection\n");
  uip_listen(HTONS(51719));

  if(uip_connected())
  {
        printf("Connection established\n");
  }

  return 0;
}

But the program seems to skip the listening part because it simply prints hello world and establishing connection before exiting. I would have thought that because of the uip_listen() function, that the program would go into a sort of infinite loop while waiting for a connection request (that is how the full stack TCP/IP library, winsock, handles things).

Is this not the correct way to listen for a connection on a certain port using the uIP library? I would appreciate any help!

UPDATE

I've tried inserting the listening in a while loop:

printf("Establishing connection\n");

int c;

  while(1)
  {
    uip_listen(HTONS(51719));
    if(c = uip_connected() != 0)
    {
      printf("Connection established\n");
      break;
    }

But it still won't connect from the remost host.
}

来源:https://stackoverflow.com/questions/23496880/uip-listen-function-not-waiting-to-listen-for-connections-uip-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!