I can't figure out to send multiple restful messages to a server

24 views
Skip to first unread message

King David

unread,
Oct 19, 2015, 2:12:49 PM10/19/15
to mongoose-users
Please assist.  I am a newbie.  I was able to get the sample restful_server and restful_client to work with the client successfully sending one message to the server.  Problem is that the application I am writing has to send multiple messages to the server. No matter what I do, I can only get to send successfully the first time and later requests are ignored.  Can someone please show me a sample that sends 3 or 4 messages to a server queued up ?   I really appreciate it.  I promise I have read all the documentation but can't really figure a way.  I have also extensively googled for sample codes but to no avail.

Thanks very much

King David

unread,
Oct 19, 2015, 8:51:08 PM10/19/15
to mongoose-users
Okay, found the solution.  Actually, I realized that I don't need to use mongoose to send out a url request.  I just went ahead and used the libcurl library to send the urls that the restful_server from mongoose is receiving.  Thanks guys!

Sergey Lyubka

unread,
Oct 20, 2015, 5:08:30 AM10/20/15
to mongoose-users
Hi,
Could you share your code please?



--
You received this message because you are subscribed to the Google Groups "mongoose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-user...@googlegroups.com.
To post to this group, send email to mongoos...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongoose-users.
For more options, visit https://groups.google.com/d/optout.

King David

unread,
Oct 20, 2015, 5:43:13 PM10/20/15
to mongoose-users
On Tuesday, October 20, 2015 at 5:08:30 AM UTC-4, Sergey Lyubka wrote:
Hi,
Could you share your code please?


Wow, flattered to be asked to post code :)

Actually it is such simple code that sends a url using the libcurl library.  I made a loop that cycles 5 times sending each time a different url that will be received by a restful server written using mongoose. (hopefully when I write the final code it will be sending like 50 urls per second)

Thanks


#include <stdlib.h>
#include <stdio.h>
#include <curl/curl.h>

int sendCurl(char *msg1)
{
  CURL *curl;
  CURLcode res;

  curl_global_init(CURL_GLOBAL_ALL);

  curl = curl_easy_init();

  if(curl) {

     printf("sending='%s'\n", msg1);

     curl_easy_setopt(curl, CURLOPT_URL, msg1);
 
     res = curl_easy_perform(curl);

     if(res != CURLE_OK)
        printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));

     curl_easy_cleanup(curl);

   }

   curl_global_cleanup();

   return 0;
  
}


int main() {

        int y,c,x = 0;
        char *clientRequest[200];
char restfulServer[100];

        snprintf(restfulServer, REQLEN, "http://serverIP:port");

        while (1)
        {
            printf("Enter:\n");
            c = 0;
            c=getchar();

            while (c != '\n')
                c=getchar();

            if (x++==5)
                break;

            snprintf(clientRequest, sizeof(clientRequest), "%s/n1?msg=bodyofmsgno%i", restfulServer, x);

            sendCurl(clientRequest);

        }

        return 1;

}
Reply all
Reply to author
Forward
0 new messages