[En-Nut-Discussion] Getting HTML output via HTTP
Nelu
nelucociag at yahoo.com
Tue Sep 11 09:42:44 CEST 2007
Hi everyone,
I'm new by ethernut /nut-os programming.
>From my C application , I want to read the output of embedded web server.
I'm trying to use Unix socket, connect to embedded web server and then
send/receive
data using write/read methods. The problem is that function 'connect' fails
every time when
try to connect. The embedded web server is running, I can load
http://10.0.0.116 in my browser.
There is the sample application I have used:
int socket_connect(char *ip_addr, in_port_t port){
struct sockaddr_in addr;
int on = 1, sock;
inet_aton(ip_addr, &addr.sin_addr);
addr.sin_port = htons(port);
addr.sin_family = AF_INET;
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&on,
sizeof(int));
if(sock == -1){
perror("setsockopt");
exit(1);
}
if(connect(sock, (struct sockaddr *)&addr, sizeof(struct
sockaddr_in)) == -1){
perror("connect");
exit(1);
}
return sock;
}
#define BUFFER_SIZE 1024
int main(int argc, char *argv[]){
int fd;
char buffer[BUFFER_SIZE];
fd = socket_connect("10.0.0.116", 80);
write(fd, "GET /\r\n", strlen("GET /\r\n"));
bzero(buffer, BUFFER_SIZE);
while(read(fd, buffer, BUFFER_SIZE - 1) != 0){
fprintf(stderr, "%s", buffer);
bzero(buffer, BUFFER_SIZE);
}
shutdown(fd, SHUT_RDWR);
close(fd);
return 0;
}
Any help will be useful.
Does anybody knows where I can find some sample code?
Thanks in advance,
Nelu Cociag
--
View this message in context: http://www.nabble.com/Getting-HTML-output-via-HTTP-tf4405591.html#a12568692
Sent from the MicroControllers - Ethernut mailing list archive at Nabble.com.
More information about the En-Nut-Discussion
mailing list