Connecting to cloud server socket example

Dear Forum,

Im needing to send a few dozen bytes of data to a server. 

Are there any examples of connecting to a cloud server using a socket example. 

Is it best to use the bsd sockets apis or the nx_tcp_client_socket apis?  I eventually will need to do migrate this to a ssl/tls connection.

Thanks

Matt

  • Dear Forum,
    So Moving along I am using the process to create, bind and connect the socket. Then allocate and append a packet. finally socket send. So I think I have that part down. What Im wondering now is about adding extra data to the path. I have xyz.com as a path, but I need to add more info to the path, so that it looks like "xyz.com/api?ns=ImageManager/STUFF"
    I can resolve the ip of xyz.com with dns, but how should the rest of the that path be passed?

    The first part of the payload Im sending is "PUT /cgi-bin/process.cgi HTTP/1.1\n"
    Should "/api?ns=ImageManager/STUFF" be place at the beginning of that part of the payload or is there another process for this?

    Thank you
    Matt
  • In reply to rupertm:

    Hello Matt,

    Seems like you're attempting to implement functionality similar to HTTP client (which is recommended for cloud connectivity, as NetX HTTP module is not fully HTTP/1.1 compliant). Once you resolve xyz.com with DNS, your request (GET or PUT) should point to xyz.com/api?ns=ImageManager/STUFF. It's also likely that you'll need to separately provide a host name in your header.

    Regards

  • In reply to Renesas Karol:

    Hi Karol,

    So when using the nx_http_client_create, nx_http_client_put_start and so on to send a packet to a server how do you define the port number? Or is it fixed at 80 when using the http client library? Im not using 80 and looking to use something else?

    Thanks
    Matt
  • In reply to rupertm:

    Hi Matt,

    The port number is defined in nx_http_client.h and you can edit this line and change it.

    #define NX_HTTP_SERVER_PORT 80 /* Port for HTTP server */

    The trick is now to prevent this file from getting overwritten by the build process by setting it's properties to read only.

    -Gary
  • In reply to garyj:

    Matt,

    I forget to mention to add the NetX source & ThreadX source to you project so that the prebuild libraries won't be used.

    -Gary
  • In reply to garyj:

    Hi Gary,

    Ok, Ill give that a shot. The read only property should then prevent the SSC from overwriting the .h file sufficiently.

    On a repeating write to the remote server port, Im guessing I need to use both the two commands below to not consume all the stack over time? Or is releasing the packet good enough?

    status = nx_packet_release(my_packet);
    status = nx_http_client_delete(&my_client);


    Thanks
    Matt
  • In reply to rupertm:

    Hey Gary,

    So Im basically following the example for the http client out of the manual. But I am getting this error which Im trying to understand. Maybe you can point me in the right direction. Its Error (0x38) which is from NetX which is Socket is not in a connected state. Im getting it from the following, nx_http_client_put_start. I guess the question is how do I get the socket into a connected state. I did not specifically see any further commands needed to be executed after the client was created. Or is that returning saying it was not able to connect to the server on the other end?

    /* Create an HTTP client instance. */
    status = nx_http_client_create(&my_client, "MyClient", &g_http_ip, &g_http_packet_pool, 600);

    /* Prepare to send the simple 103-byte HTML file to the Server. */
    serverIP = IP_ADDRESS(192,168,1,205);
    status = nx_http_client_put_start(&my_client, serverIP, "/test.htm", "user", "password", 103, 600);

    Thanks
    Matt
  • In reply to garyj:

    Hi Gary,
    Ok, so digging further I just discovered this #define NX_HTTP_SERVER_PORT 80 /* Port for HTTP server */ is also used for the http server I have running. So if I need the server to run on port 80, but I need to connect as a client to another server on say port 8888, what do I do? It seems like there needs to be a #define NX_HTTP_CLIENT_PORT 80. Is this a limitation?

    Thanks
    Matt
  • In reply to rupertm:

    Hi Matt,

    Unfortunately, the actual client code is in protected source from Express Logic and can not be edited.
    I will raise this issue internally and put it on the list for improvements.

    -Gary
  • In reply to rupertm:

    Hello Matt,

    NX_HTTP_SERVER_PORT is defined separately for client and server (nx_http_client.h and nx_http_server.h, respectively). I can't see any references between server source and client header and vice versa, so I suppose you can go ahead and modify NX_HTTP_SERVER_PORT inside nx_http_client.h without imposing any changes in the behaviour of the server module.

    Regards
  • In reply to Renesas Karol:

    Hi Karol, and Gary

    What happens is when compiling Im getting a warning saying Im getting a incompatible redefinition. The define name is the same in both the NX_http_client.h and the NX_http_server.h. So if one is using both server and client with unique ports things dont work so well. When connecting to a cloud server I can see myself needing to connect to many different port numbers. Changing them basically on the fly as I send some data here or there. Would be nice is there was a way to define the port when the creating the client with http_client create.

    Warning[Pe047]: incompatible redefinition of macro "NX_HTTP_SERVER_PORT" (declared at line 224 of "C:\Renesas\workspace\SK_foundation_IAR\synergy\ssp\inc\framework\el\ C:\Renesas\workspace\SK_foundation_IAR\synergy\ssp\inc\framework\el\nx_application_layer\nx_http_client.h 160
    nx_application_layer\nx_http_server.h")

    Im very interested in seeing how this is improved and how this gets done when the Renesas Security framework is released later this year. The integrated security framework is so badly needed at least in my industry.

    So Karol, Im going to switch back to doing the socket process to create, bind and connect the socket where I can control the port numbers unless you think there is still a better ways to do this? Are there any good examples references of the process to create, bind and connect the client sockets you have around. You have had some great reference apps in the past.

    Thank you guys!
    Matt
  • In reply to rupertm:

    Hello Matt,

    The request is already in place to provide a separate setting for the server and client port. You can resolve the warning in your source by doing #undef NX_HTTP_SERVER_PORT between #include nx_http_server.h and #include nx_http_client.h (unless they're found in the generated code). The simple socket connectivity can work well also - if you have production/development license then you can look through HTTP Client/Server source to see how this is achieved using nx_tcp_* functions.

    Regards
  • In reply to Renesas Karol:

    Thanks Karol!!

    Ok, Ill look through the source. But you dont have one of your straight forward demos for doing that stuff?

    Thanks again.
    Matt
  • In reply to rupertm:

    Hello Matt,

    We don't have any example applications that specifically implement HTTP GET/POST requests on TCP, however you can refer to the TCP examples I've posted in the past for basic TCP processing flow: renesasrulz.com/.../netx-capabilities-on-s7.

    Regards
  • In reply to Renesas Karol:

    Ok, Great. Thank you Karol!!