RTCS TCP/IP socket client setup trouble

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RTCS TCP/IP socket client setup trouble

Jump to solution
3,618 Views
khoanguyen
Contributor I

Hi,

I'm currently working with MQX 3.8.1, Codewarrior 10.2, and the Kinetis K60 tower module, and I'm having trouble connecting using my tower as a client to my laptop. I was wondering if anyone could tell me what I'm doing wrong.

Setup:

  • Set laptop ethernet port to IP: 192.168.3.101 and gateway: 192.168.3.1
  • trying to open a socket on the K60 to act as a client to my laptop (acting as a server)
  • attempting to reach any website to prove that it works, google.com or any website

What does work so far:

  • Ethernet connection is successful and RTCS is up and running (started a new MQX project and added RTCS/shell support which ran successfully)
  • I set up an error checking for binding the socket and it didn't hit the error so I'm assuming that binding works.

Problems:

  • Hit error message for connecting the socket so it isn't connecting the socket.

Questions:

  1. Is the destination IP address supposed to be the IP for google or the server. (I tried using 192.168.1.101 which is the IP of my server but that failed)
  2. what is being assigned to these declarations (i've noticed these keep popping up in numerous examples)
    1.   _ip_address   ipaddr;
    2. socketaddr_in    addr;
  3. Are there any other examples besides the Twitter example and the socket training video/pdf? These seem to have more examples for the server side but I'm trying to set up the K60 as a client to a database later on.

Code:

#define HOST   "google.com"
#define DESTIP   IPADDR(192,168,3,1)

#define ENET_DEVICE 0

#define RTCS_DHCP 0

#define ENET_IPADDR IPADDR(192,168,3,101)

#define ENET_IPMASK IPADDR(255,255,255,0)

#define ENET_GATEWAY IPADDR(192,168,3,1)

#define RTCS_PPP 0


void connect_task(uint_32 initial_data)

{

    _ip_address     ipaddr;

    uint_32            sock;

    uint_32            result;

    sockaddr_in        addr;

    char*            test = "This is a test for data stream";

   

    while(1)

    {

        if (_mutex_lock(&print_mutex) != MQX_OK)

            {

                printf("Mutex lock failed.\n");

                _task_block();

            }   

    rtcs_init();

   

    addr.sin_family     = AF_INET;

    addr.sin_port        = 80;

    addr.sin_addr.s_addr = DESTIP;

   

    sock = socket(AF_INET, SOCK_STREAM, 0);

    result = bind(sock, &addr, sizeof(addr));

    if(result != RTCS_OK)

    {

        printf("ERROR the socket could not be bound");

        return;

    }

   

    addr.sin_port = 80;

   addr.sin_addr.s_addr = ipaddr;

   

    result = connect(sock, &addr, sizeof(addr));

    if(result != RTCS_OK)

        {

            printf("ERROR the socket could not CONNECT");

        }

    else

    {

        printf("Connected to %lx, port %d",addr.sin_addr.s_addr, addr.sin_port);

    }

   

    printf("\nREADY TO SEND DATA!!!!!!!!!!!!!!!!!");

   

    _mutex_unlock(&print_mutex);

    _task_block();

    }

}



Thanks,


Khoa Nguyen

Labels (1)
Tags (5)
0 Kudos
Reply
1 Solution
1,629 Views
Luis_Garabo
NXP TechSupport
NXP TechSupport

Perhaps you have a firewall preventing the port to be available for connections. Try to disable the firewall of internet security programs.

I have created and example that I have tested with Socketest. I am attaching here. It is pretty simple. It sends data from the socket to the serial and from the serial to the socket.

Hope this helps.

Regards,

-Garabo

View solution in original post

0 Kudos
Reply
4 Replies
1,629 Views
Luis_Garabo
NXP TechSupport
NXP TechSupport

Hi Khoa,

Perhaps this appnote can help you http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4417.pdf

The source code is provided here:

http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4417SW.zip

this code is doing the same you are trying. Crop the code that does the socket negotiation and let me know if worked.

Good luck,

Best Regards,

Garabo

1,629 Views
khoanguyen
Contributor I

Hi,

I've already referred to this AN for reference and I'm able to establish a TCP connection to a designated endpoint but the send function for sockets is blocking because the connection hasn't been accepted. Is there a program I can use to test this? I've using a program called SocketTest v3.0.0 which created a server TCP socket on my windows laptop to listen for incoming connections but it didn't seem to work.

Also, since the send function is blocked, due to not having a server accept the connection, will the function automatically go back into ready whenever the connection is accepeted?

Thanks,

Khoa Nguyen

0 Kudos
Reply
1,629 Views
oscarguallar
Contributor I

Hi Khoa,

I have the same issue that you had with the TCP/IP socket. The connection is not accepted,, then blocks the task.

How did you fix the problem?

Thanks.

Oscar


0 Kudos
Reply
1,630 Views
Luis_Garabo
NXP TechSupport
NXP TechSupport

Perhaps you have a firewall preventing the port to be available for connections. Try to disable the firewall of internet security programs.

I have created and example that I have tested with Socketest. I am attaching here. It is pretty simple. It sends data from the socket to the serial and from the serial to the socket.

Hope this helps.

Regards,

-Garabo

0 Kudos
Reply