I'm having some trouble with a socket web client. It should basically just connect to enter addr/URL and port through a set server using sockets. I've gotten way off track and I ned some help starightening out what I hae and what I need to get it to run. It should connect then the user will enter GET / HTTP/1.0 followed by a blank line and it will reply with the document HTML.
Any help would be greatly appreciated...Thank you in advance.
Code:
#include "unp.h"
#define MAXN 16384 /* max #bytes requested */
int
main(int argc, char **argv)
{
int j, fd;
pid_t pid;
ssize_t n;
char request[MAXLINE], reply[MAXN];
if (argc != 2)
err_quit("usage: client <hostname or IPaddr> <port>");
nbytes = MAXN;
snprintf(request, sizeof(request), "%d\n", nbytes);
if ( (pid = Fork()) == 0) { /* child */
for (j = 0; j < 1; j++) { /* loop */
fd = Tcp_connect(argv[1], argv[2]);
Write(fd, request, strlen(request));
if ( (n = Readn(fd, reply, nbytes)) != nbytes)
err_quit("server returned %d bytes", n);
Close(fd); /* TIME_WAIT on client, not server */
}
exit (0)
}
while (wait(NULL) > 0)
;
if (errno != ECHILD)
err_sys("wait error");
exit(0);
}
Please use [code][/code]Tags