How to receive and transmit buffer in C ++

0

Good morning I am trying to create a proxy for learning purposes, but I have a failure when I want to re-transmit the buffer from the server to the client, here's my function:

send(Socket_Server,Reques,strlen(Request),0);
int receive = 0;
while(receive = recv(Socket_Server,buff,BUFFER_SIZE,0) > 0){
    send(Socket_Server,buff,BUFFER_SIZE,0);
}   

How can I create the proper function that Chunk-Encoding can handle and not lose information in the re-transmission?

    
asked by tee 01.03.2017 в 18:40
source

1 answer

1
receive = recv(Socket_Server,buff,BUFFER_SIZE,0)

It is assumed that there you are receiving receive bytes of data and what you intend is to forward only those data ... not all the buffer, right?

Then send should look like this:

send(Socket_Server,buff,receive,0);

What your code does is transmit the entire buffer, which will contain, as a general rule, garbage at the end of it.

The complete code:

send(Socket_Server,Reques,strlen(Request),0);
int receive = 0;
while(receive = recv(Socket_Server,buff,BUFFER_SIZE,0) > 0){
    send(Socket_Server,buff,receive,0);
}
    
answered by 02.03.2017 в 08:41