[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] Using lwip for writing a minimal HTTP proxy
From: |
Mandeep Sandhu |
Subject: |
[lwip-users] Using lwip for writing a minimal HTTP proxy |
Date: |
Thu, 24 Sep 2009 22:35:11 +0530 |
Hi All,
I'm implementing a very minimal HTTP proxy server, using lwIP (1.3.1)
in "sequential" mode.
I've based my code on the sample http webserver that is provided along
with lwIP (httpd_sequential.c). I'm using ecos.
The way the server works is simple. Eg: A request like http://<my
IP>/local/index.html from client, will cause it to serve a local page.
Whereas http://<my IP>/REMOTE/index.html will cause it to "proxy" the
client request to another HTTP server (pre-configured).
I'm able to do the local part successfully, i.e server local content
(the index.html response is created on the fly, it's not a file).
The problem starts when I try to proxy the request to another server.
Say the clients connection with my server is "client_conn". In the
main event loop of my server, for proxy requests, I do the following:
1) proxy_conn = netconn_new(NETCONN_TCP);
2) netconn_connect( proxy_conn, <IP addr of other server>, <other
server's listening port> );
3) netconn_write( proxy_conn, <data to be proxied>, <length>, NETCONN_COPY);
4) Listen for resp (this code is based on the TCP echo example):
while ((proxy_resp = netconn_recv(proxy_conn)) != NULL ) {
do {
netbuf_data(proxy_resp, &data, &len);
//Write response to the client
err = netconn_write(client_conn, data, len, NETCONN_COPY);
if (err != ERR_OK) {
goto error; // some error handler
}
} while (netbuf_next(proxy_resp) >= 0);
netbuf_delete(proxy_resp);
}
My problem happens at step 2. The error code returned is "-5" i.e ERR_ABRT.
Is this the right approach to do this? Why is the "connect" failing?
Is it because in sequential mode I cannot initiate a second TCP
connection while the first one is not closed?
I'm new to TCP, so pardon me if I'm missing something obvious! :)
Thanks,
-mandeep
- [lwip-users] Using lwip for writing a minimal HTTP proxy,
Mandeep Sandhu <=