[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] Asynchronous events.
From: |
Nick Thomas |
Subject: |
[lwip-users] Asynchronous events. |
Date: |
Fri, 12 Sep 2008 16:54:12 +0100 |
Hi,
I am trying to implement a simple client program. I have got the simple
httpd server app working OK in lwip, and I can connect to it using a browser
on my PC, and I see my simple web page. So far so good.
But, now I would like to use lwip as a client, in order to get it to go to
an external website (not lwip based), and download the home page using the
"GET / HTTP/1.1\r\n\r\n" code.
I tried using the netconn_XXX, and netbuf_XXX commands, and couldn't get it
to work, it simply blocks in the netconn_recv() waiting for data.
Then I tried the sockets api call (which I am more familiar with) - like
this:
-- SNIP --
int sd;
struct sockaddr_in saddr;
struct sockaddr_in local;
int len, sent;
char buffer[1024];
sd = socket(AF_INET, SOCK_STREAM, 0);
printf("nettest: got socket\r\n");
/* prepare local address */
memset(&local, 0, sizeof(local));
local.sin_family = AF_INET;
local.sin_port = htons(INADDR_ANY);
local.sin_addr.s_addr = htonl(INADDR_ANY);
/* Is this really necessary for a client program? */
bind( sd, (struct sockaddr *)&local, sizeof(local) );
memset(&saddr, 0, sizeof(saddr));
saddr.sin_len = sizeof(saddr);
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = inet_addr("192.168.0.100"); /* my local web
server
*/
saddr.sin_port = htons(80); /* http server. */
printf("nettest: server setup\r\n");
connect( sd, (struct sockaddr *) &saddr, sizeof(saddr) );
printf("nettest: connected\r\n");
sent = send(sd, (void *)my_hdr, sizeof(my_hdr), 0);
printf("nettest: sent %d bytes\r\n", sent);
len = recv( sd, buffer, sizeof(buffer), 0 );
printf("Received %d bytes\r\n", len); /* NEVER GETS HERE */
-- END --
I now see that the recv() call hangs. I suppose it is waiting for some data.
In the Win32 world I could us a call like:
iRc = WSAAsyncSelect( client.sock, hWnd, WM_WSASYNC,
FD_CONNECT|FD_READ|FD_CLOSE );
Which would provide a callback method to inform my app when some data
arrives. Is there anything like this in lwip?
Thanks in advance.
Regards
Nick
-----------------------------
Nick Thomas
Email: address@hidden
- [lwip-users] Asynchronous events.,
Nick Thomas <=