Hi Fabrizio! On Wed, Mar 26, 2014 at 10:24 AM, Fabrizio Dini <dini.fabri...@gmail.com>wrote:
> Hi Sergey! Hi everybody! > > For a personal project of mine, I am trying to send http requests to an > external web/cgi server. I managed to connect to the remote server with > mg_connect() and get the event handler called with MG_CONNECT event. > However, I wasn't able to forge a correct http GET request to a simple web > server. I do get the request to be sent via my eth0 interface (I verified > that with wireshark), but both the request and the response I get looks > strange. > > I could copy/paste them here, but that would be quite a lot of text... > Consider publishing your project on github. Then commenting and patching wouldn't be a problem! > Instead, it would suffice to have a little more documentation on how > mg_connect() work and how a client is expected to work with mongoose. In > particular, since my application is supposed to serve local files and CGIs > also, I would like to know if it is a good idea to use two separate > mongoose servers to handle incoming and outgoing requests, or it is ok to > use a single server for both. > > Another critical question is: what are the correct return codes to be used > in the event handler for MG_CONNECT, MG_REPLY and MG_CLOSE events? And, > last but not least, what is the correct way to forge and send the http > request? I am trying by sending text with mg_send_data(), but I am not sure > I am doing it right. An insight of how mg_poll_server() works with outgoing > requests would also be helpful. > mongoose.h<https://github.com/cesanta/mongoose/blob/94f63787bb2be723151306d24e3b8d78cd353e04/mongoose.h#L65>has some crude documentation on callback return values. I'll extend the API doc. You can take a look at mg_connect() example code in unit_test.c<https://github.com/cesanta/mongoose/blob/master/examples/unit_test.c#L438>, particularly, evh1() and evh2() functions. mg_connect() creates a new connection, and adds it to the list of connections handled by a server. On each iteration of mg_poll_server(), all connections are multiplexed by select() syscall. All sockets are non-blocking, therefore connect() syscall that is done by mg_connect() just "schedules" the actual connection. select() will return the socket as ready on success or failure, and mongoose calls MG_CONNECT event, indicating success or failure through mg_connection::status_code. On success, usual mg_printf() could be used to send a request. When reply is received, mongoose sends MG_REPLY. Hope that helps, Sergey. -- 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-users+unsubscr...@googlegroups.com. To post to this group, send email to mongoose-users@googlegroups.com. Visit this group at http://groups.google.com/group/mongoose-users. For more options, visit https://groups.google.com/d/optout.