Thread: Web Server Issues in C

  1. #1
    Registered User
    Join Date
    Oct 2009

    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.
    HTTP/1.1 200 OK
    Content-Type: text/plain
    Content-Length: 139
    Connection: Close

    My socket is set up to listen, and here's my valid request 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;
      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);
       write(fd, message, strlen(message));
       fflush(fp); //flush
       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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.

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, 11:21 PM
  3. SWEBS Web Server
    By nickname_changed in forum A Brief History of
    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, 10:24 PM
  5. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM