http/1.1 persistent connection issue.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello all,

I am trying to develop a little program that should be able to send
http/1.1 requests.  This is all running fine but I get some problems
with the persistent connection.

I mean I can send one request in my http connection but the second one
does not seem to work properly.

Maybe I made an error in my code, maybe I do not understand something in
http/1.1 ?

Can somebody help me please ? ... many thks.

----- source code -------

#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <strings.h>
#include <stdio.h>
#include <stdlib.h>

const static char GET [] =
{
    "GET / HTTP/1.1\r\n"
    "Host: 127.0.0.1\r\n"
    "User-Agent: UserAgent\r\n"
    "Connection: keep-alive\r\n"
    "\r\n"
};

int main(int argc, char **argv)
{
    int bufsize = 0;
    char buffer[1024] = "\n";

    int32_t i32SocketFD = socket(PF_INET, SOCK_STREAM, 0);
    if (-1 == i32SocketFD) {
        fprintf(stderr, "Error i32SocketFD");
        exit(-1);
    }
    struct sockaddr_in stSockAddr;
    bzero(&stSockAddr, sizeof(stSockAddr));
    stSockAddr.sin_family = AF_INET;
    stSockAddr.sin_port = htons(80);
    int32_t i32Res = inet_pton(AF_INET, "127.0.0.1", (void *)
&stSockAddr.sin_addr);
    if (0 > i32Res){
        fprintf(stderr, "i32Res");
        exit(-1);
    } else if (0 == i32Res){
        fprintf(stderr, "Error i32Res 2");
        exit(-1);
    }

    if (-1 == connect(i32SocketFD, (struct sockaddr *) &stSockAddr,
sizeof(stSockAddr))) {
        fprintf(stderr, "Error connect");
        exit(-1);
    }

    if (send(i32SocketFD, GET, strlen(GET), 0) == -1) {
        fprintf(stderr, "Error sending data.");
    }

    while((bufsize = read(i32SocketFD, buffer, sizeof(buffer) - 1))){
        printf("%s",buffer);
    }

    if (send(i32SocketFD, GET, strlen(GET), 0) == -1) {
        fprintf(stderr, "Error sending data.");
    }

    while((bufsize = read(i32SocketFD, buffer, sizeof(buffer) - 1))){
        printf("%s",buffer);
    }

    shutdown(i32SocketFD, 2);
    close(i32SocketFD);
}
-----------------------------------------------------------------
ATTENTION:
The information in this electronic mail message is private and
confidential, and only intended for the addressee. Should you
receive this message by mistake, you are hereby notified that
any disclosure, reproduction, distribution or use of this
message is strictly prohibited. Please inform the sender by
reply transmission and delete the message without copying or
opening it.

Messages and attachments are scanned for all viruses known.
If this message contains password-protected attachments, the
files have NOT been scanned for viruses by the ING mail domain.
Always scan attachments before opening them.
-----------------------------------------------------------------



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux