This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

NDK - connect fails, maybe I am not getting IP ...

Hi,

I am trying to run tcp client to connect to server application, simply send and receive data.

I am getting error on connect, below is the detailed data of the system I am running and the error I am receiving.

I will provide the following data in this post in the following order:

1) Test that I made in order to verify my tcp server is OK

2) The components versions that I am running

3) My code

4) The output of the running 

5) Additional two tests I performed and this is why I am suspecting I am not getting even IP

6) two updates with additional important data that I added

 Test that I made in order to verify my tcp server is OK

Please note:

I tested my tcp server before running the program this way:

- Downloaded tcp server and tcp client programs to my pc

- verified my ip (using ipconfig on my windows computer) and running the server waiting on port 2222

- running the tcp client software to connect to my ip and port 2222

- connection success and i manage to transfer data between both.

Now I closed the tcp client program, restarted tcp server, verified my ip again and run my program I wrote, it fails.


 The components versions that I am running

ccs: 5.4.0.00091

bios: 6_35_01_29

pspdrivers: 01_30_01

nsp: nsp_1_10_02_09

ndk: ndk_2_22_03_20

xdctools: 3_25_00_48

xgconf:  I selected "global network settings", "http", "tcp", "ip" and enable IPv6. I also tried to activate the "dhcp client".

My code

Creating the task:

Task_Params taskParams;

    Task_Params_init(&taskParams);

    taskParams.stackSize = 512*4;

    taskParams.priority = 1;

    taskParams.arg0 = NULL;

    taskParams.arg1 = NULL;

    task = Task_create(tcpTask,&taskParams, &eb);

The task:

Void tcpTask(UArg a0, UArg a1)

  {

   SOCKET s;

  struct sockaddr_in sin1;

  int i;

  char *pBuf = 0;

  struct timeval timeout;

  Task_sleep(10000); //waiting 10  seconds, just in case for the test - so all ip setting will be ready... in next vers i will look for some event

  // Allocate the file descriptor environment for this Task

  if (!fdOpenSession( (HANDLE)Task_self() ))

  return;

  printf("\n== Start TCP Echo Client Test ==\n");

  IPN IPAddr = inet_addr("192.168.14.197"); //the ip of my computer where I am running the tcp server program

   // Create test socket

   s = socket(AF_INET, SOCK_STREAMNC, IPPROTO_TCP);

  if( s == INVALID_SOCKET )

  {

      printf("failed socket create (%d)\n",fdError());

      goto leave;

  }

  // Prepare address for connect

  bzero( &sin1, sizeof(struct sockaddr_in) );

  sin1.sin_family = AF_INET;

  sin1.sin_len = sizeof( sin1 );

  sin1.sin_addr.s_addr = IPAddr;

  sin1.sin_port = htons(2222); //the port my server is listening to

  // Configure our Tx and Rx timeout to be 5 seconds

  timeout.tv_sec = 5;

  timeout.tv_usec = 0;

  setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof( timeout ) );

  setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof( timeout ) );

  // Connect socket

  if( connect( s, (PSA) &sin1, sizeof(sin1) ) < 0 )

  {

  printf("failed connect (%d)\n",fdError());

  goto leave;

  }

The output of the running 

Using default MAC address

Using MAC Address: 00-08-ee-03-14-99

enter main()

00000.000 MAC Address = 00-08-ee-03-14-99

00000.000 EMAC should be up and running

00000.000 EMAC has been started successfully

00000.000 Registeration of the EMAC Successful

Service Status: DHCPC    : Enabled  :          : 000

Service Status: DHCPC    : Enabled  : Running  : 000

Link Status: 100Mb/s Full Duplex on PHY 0

== Start TCP Echo Client Test ==

failed connect (6)

== End TCP Echo Client Test ==

Service Status: DHCPC    : Enabled  : Fault    : 002

Additional two tests I performed and this is why I am suspecting I am not getting even IP

TEST 1
I am running IP SCAN to my network, I am getting the same list of IPS with or without running my program
TEST 2
In the XGCONF I am disabling the DHCP CLIENT box and also in the IP I am disabling the get ip from dhcp and setting fixed IP (I choose one not in use).
This time I do not get out from the connect() ! to the next line (I am not getting into the error, but it does not een get to the line after.
I am getting the following after running the code:
Using default MAC address
Using MAC Address: 00-08-ee-03-14-99
enter main()
00000.000 MAC Address = 00-08-ee-03-14-99
00000.000 EMAC should be up and running
00000.000 EMAC has been started successfully
00000.000 Registeration of the EMAC Successful
Network Added: If-1:192.168.14.192
Link Status: 100Mb/s Full Duplex on PHY 0
== Start TCP Echo Client Test ==
-------
Update:
Additional run that I tried, configured in cgconf only tcp  and ip, I got this after running the code


== Start TCP Echo Client Test ==
failed connect (65)
== End TCP Echo Client Test =

Second important update:

i openned my router statistics file, it seems that the device is detected and also the router gives an ip (when fixed ip, the router detects the Mac of the device and the ip I gave, when dhcp, the router shows the Mac and an ip that it gave to the device!)

-----

Help will be appreciated.....
THANKS!!!
  • Hi Gaby,

    Where is your tcpTask create code being called? main() or from within another task?

    Thanks,

    -- Emmanuel

  • Hi,

    I am calling it from my main.

    I had other stuff in the project (tasks, timer, spi...) but I commented it all.

    Currently all I have in my main you can see below.

    Thanks!

    My main looks like this:

    /*
    * ======== main ========
    */
    Void main()
    {
        Error_Block eb;
        Task_Handle task;

        Task_Params_init(&taskParams);

        taskParams.stackSize = 512*4;
        taskParams.priority = 1; 
        taskParams.arg0 = NULL;//(xdc_UArg)&sSpiPort;
        taskParams.arg1 = NULL;//(xdc_UArg)&sSpiParams;

        System_printf("enter main()\n");

        Error_init(&eb);

         task = Task_create(tcpTask,&taskParams, &eb);

        if (task == NULL) {

            System_printf("Task_create() failed!\n");
            BIOS_exit(0);
        }

        BIOS_start(); /* enable interrupts and start SYS/BIOS */

    }

  • Hi Gaby,

    When the Task create code is in main, it will run before the stack has obtained an IP address, thus causing the socket code to fail.  Try moving the Task create code to the NDK's "IP address hook function".  This will be called whenever an IP address is added or removed (Task will be created once the IP address is obtained).  

    Please note, the function is also called when the address is removed, so your code should make sure not to create the Task again.

    Thanks,

    -- Emmanuel

  • Thanks, the ideas you gave were good and helped.

    I have it working...

    Well it took some hours as eventually I replaced bard and second one was OK... maybe something with the ethernet connecter, I paid attentin that yellow led was blinking but nothing about green one.

    After I replaced and after I implemented your ideas it was OK.

    THANKS!!!