Thread: socket programming recv function

  1. #1

    socket programming recv function

    on my lan is running a webserver so when i wrote a simple socket application like

    char buffer[32];
    struct sockaddr_in * address= new (struct sockaddr_in);
    printf("connect %d \n",connect(sock,(struct sockaddr *)address,sizeof(*address)));
    printf("%d ",send(sock,"GET /index.htm",14,0));

    till send everything is working fine but why i am not able to retreive the index.htm page back .

    i have tried the same program on my linux box too but to no avail .what is the prob am i missing something ...

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > printf("%d ",send(sock,"GET /index.htm",14,0));
    Do you need to send a newline with this as well?

    > recv(sock,buffer,32,0);
    This doesn't know how much data will be returned, and in particular, it can return the data in fragments. It's up to you to reassemble the data into its proper form.
    int n;
    while ( (n=recv(sock,buffer,32,0)) > 0 ) {
        // do something with n bytes in buffer
    if ( n == -1 ) {
        perror( "cant recv" );
    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
    thanx it's working now ... i needed two new line characters ....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. shutdown function socket programming
    By 256Doofus in forum Networking/Device Communication
    Replies: 0
    Last Post: 10-26-2008, 04:47 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM