-1

How to end reciving data from client ?

I Wrote this code that listen on port 80
I want to get request from client browser and send response

C++ :

    while ( (l = recv(client, buff, 250, 0)) > 0){
        buff[l] = '\0';
        printf(buff);
    }
    sprintf_s(buff,"<h1>Hello World</h1>");
    send(client, buff, strlen(buff), 0);
    closesocket(client);

this while never end... and after the client's browser send request to the server my code stop on recv() function..... it means recv() function never return zero....
What should i do to know that receving data has finished ?

HERO
  • 33
  • 1
  • 5

1 Answers1

0

You work with network requests in a wrong way.

recv function in blocking mode returns zero when a connection has been closed. It means that you cannot send data after recv returned zero.

In you case you should parse the received data and wait for end-of-request marker (empty line).

Andrey Nasonov
  • 2,619
  • 12
  • 26