Implementing a forwarding web cache

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Van Dugall
    New Member
    • Mar 2009
    • 6

    Implementing a forwarding web cache

    What can do to make this client file into a Forward Web Cache -- for static contents, usng the if-modified approach for coherence... I'm not that comfortable with C but it is the only language I know how to make a connect between to terminals. I was thinking using a hash table and each key is a linked list to store
    but I confused about how to parse the strings and even test if my cache even works??

    This is the client file:

    #include <string.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <netdb.h>

    #define SERVER_PORT 5432
    #define MAX_LINE 256

    int
    main(int argc, char * argv[])
    {
    FILE *fp;
    struct hostent * hp;
    struct sockaddr_in sin;
    char *host;
    char buf[MAX_LINE];
    int s;
    int len;
    char message[1024];

    if (argc==2) {
    host = argv[1];
    }

    else {
    fprintf(stderr, "usage: simplex-talk host\n");
    exit(1);
    }

    hp = gethostbyname(h ost);
    if (!hp) {
    fprintf(stderr, "simplex-talk: unknown host: %s\n", host);
    exit(1);
    }

    bzero((char *)&sin, sizeof(sin));
    sin.sin_family = AF_INET;
    bcopy(hp->h_addr, (char *)&sin.sin_addr , hp->h_length);
    sin.sin_port = htons(SERVER_PO RT);

    if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
    perror("simplex-talk: socket");
    exit(1);
    }
    if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
    perror("simplex-talk: connect");
    close(s);
    exit(1);
    }

    while (fgets(buf, sizeof(buf), stdin)) {
    buf[MAX_LINE-1] = '\0';
    len = strlen(buf) + 1;
    send(s, buf, len, 0);
    }
    }
  • RRick
    Recognized Expert Contributor
    • Feb 2007
    • 463

    #2
    Forward Web Caching is done on the server, so showing us the client code isn't going to help much. As far as the client is concerned, the information is the same with or without a cache. Its the response time that changes with a cache.

    In the future, please use the code tags for the source code. It helps readability.

    Your idea of using a C++ hash for linking keys to data, is a good and common approach. You need to figure out what key to use and how to identify it.

    Comment

    Working...