Web Server Issues in C

This is a discussion on Web Server Issues in C within the Networking/Device Communication forums, part of the General Programming Boards category; I am having an issue sending information to my browser on a valid request. This is the header file we ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    44

    SOLVED: Web Server Issues in C

    I am having an issue sending information to my browser on a valid request.
    This is the header file we create on a valid file, printed out to the console.
    Message:
    HTTP/1.1 200 OK
    Content-Type: text/plain
    Content-Length: 139
    Connection: Close

    0�5
    My socket is set up to listen, and here's my valid request code:
    Code:
    int return_result(int fd, char *content_type, char *buf, int numbytes) {
      FILE *fp;
      fp=fdopen(fd, "w+");
      if (fp==NULL) {
        perror("Couldn't open file");
        return -1;
      }
      char* message;
      message=malloc(sizeof(char)*MSGSIZE+sizeof(buf));
      int count=sprintf(message, "HTTP/1.1 200 OK\n\rContent-Type: %s\n\rContent-Length: %d\n\rConnection: Close\n\n%s\n\r",content_type, numbytes, &buf);
       printf("Message:\n%s\n",message);
       write(fd, message, strlen(message));
       fflush(fp); //flush
       close(fp);
       return 0;
    I don't know what I'm doing wrong.

    Thanks for any help.
    Last edited by TIMBERings; 05-03-2010 at 01:56 PM. Reason: Solved

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,418
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Web Server Issues
    By TIMBERings in forum C Programming
    Replies: 4
    Last Post: 05-03-2010, 02:15 PM
  2. Server Architecture
    By coder8137 in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-29-2008, 10:21 PM
  3. SWEBS Web Server
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 09-22-2003, 02:46 AM
  4. Web Server in Router Network...
    By Aidman in forum Tech Board
    Replies: 15
    Last Post: 01-17-2003, 09:24 PM
  5. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21