Re: Is http server and http client possbile?

"markreds81" <[email protected]>
Newsgroups gmane.comp.hardware.rabbit-semiconductor
Message-ID <[email protected]>

Yes, it is!
Server and client don't use the same socket but be sure the MAX_TCP_SOCKET_BUFFERS define is enought.

In addition keep in mind that httpc_skip_headers() and httpc_read_body() functions can take a while to complete their task due to network delays (especially if you use a slow connection like GPRS but I don't know if it is your context). So during that tasks you should yield to other costates. So try to write your own (co)function based on these ones. You can take a look to the http_client.lib source code. Here an example:

[...]
// fill buf with data to post
// blah, blah, blah
// s is a pointer to httpc_Socket structure passed as parameter to my confunction
rc = ((sock_write(s->sock, buf, i) != -1) && (sock_write(s->sock, (byte *)&ev, sizeof(ev)) != -1)) ? 0 : -EIO;
if (!rc)  {
   // waiting for a response from the server
   tm = SEC_TIMER + 5L; // wait max 5 seconds
   while ((s->state == HTTPC_STATE_HEADER) && (rc >= 0) && (tm > SEC_TIMER)) {
     // I'm not really interested in headers, I'm just waiting for the body part of the response
     rc = httpc_read_header(s, NULL, 0, 0);
     yield;
   }
   i = 0;
   while ((s->state == HTTPC_STATE_BODY) && (rc >= 0) && (i < sizeof(buf)) && (tm > SEC_TIMER)) {
      rc = httpc_read_body(s, buf + i, sizeof(buf) - i);
      if (rc > 0) {
         i += rc;
         // received a chunk of data from the server
      }
      yield;
   }
}
[...]


In my application (a datalogger connected to internet via GPRS) I wrote my cofunction and it works. I hope this is clear enought and that it can helps you.

Marco


--- In [email protected], "racqueldesign" <embeddedsupplies@...> wrote:
>
> Hi,
> 
> I have a HTTP server running and the cgi is working fine.
> I added http client and now the cgi is taking about 10 seconds to respond.
> 
> I think the cgi keeps the response to any HTTP REQUEST until the http client task is complete.  My question is, how do I get the cgi to send the response(infomation in its buffer) immediately?  I added a yield statement hoping to give control back to the http_handler but that didn't work.  I am not sure why my cgi won't send response right-away. Do you guys have any advice?
> 
> 
> while (1) {			
>   
>   costate {
>       http_handler();
>   }			
> 			
>   costate {
>     yield;  //GIVE CONTROL BACK TO http_handler(), cgi 
> 			
>     retval = httpc_init (&hsock, sock);
>     if (retval)
>     {
>        printf ("error %d calling httpc_init()\n", retval);
>     }
> 			
>     retval = httpc_post( &hsock, DEST, 80, FILENAME, NULL, PostUpdate_Msg);
>     if(retval){
> 	printf ("error %d calling httpc_post()\n", retval);
>     }
> 			
> 
>     //Skip Header reading and only read body
>     httpc_skip_headers(&hsock);   //skip header reading
>     do
>     {
> 	 retval = httpc_read_body( &hsock, PostResponse_msg, 128);
>     } while(hsock.state == HTTPC_STATE_BODY);
> 
>     httpc_close(&hsock);
>   }
> }
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.