Thread: Silly Question

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    10

    Silly Question

    I'm sure this is going to be a silly question....

    I'm trying to send a response from server to client. I am creating a buffer called response, copying the first value in and appending values that follow.

    Code:
            char response[MAX];
    
            strcpy(response, protocol); // value of protocol is HTTP/1.1
            strcat(response, " ");
            strcat(response, "200 OK");
            strcat(response, "\n");
            printf("Response: %s\n", response);
            send(nsk, response, strlen(response), 0);
    When it's received by the client I get:

    Code:
     200 OKe: HTTP/1.1
    As you can see the " 200 OK\n" appear to have overwritten "Response: HTTP/1.1"

    I've tried a few different things. Any thoughts?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Is MAX large enough for the resulting string?

    Does response contain a trailing \r character?
    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.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    10
    Quote Originally Posted by Salem View Post
    Does response contain a trailing \r character?
    That was it. When I tokenize the string, this is the last token. I was looking for "\n" instead of "\r\n".

    Thanks for the help, I knew it was going to something I just wasn't seeing.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Silly question :D
    By audinue in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 12-31-2008, 05:30 PM
  2. Silly question but..
    By swgh in forum C++ Programming
    Replies: 3
    Last Post: 05-05-2008, 12:39 PM
  3. A Silly Question!
    By MK4554 in forum C++ Programming
    Replies: 2
    Last Post: 01-13-2006, 02:49 PM
  4. Really really silly question
    By caduardo21 in forum C Programming
    Replies: 6
    Last Post: 06-06-2005, 09:33 AM
  5. silly question??
    By swgh in forum Game Programming
    Replies: 4
    Last Post: 04-27-2005, 08:50 PM