Sending big data> 1 MB via Windows Sockets using the send function

I want to send a large message> 1 MB via windows send api sockets. Is there an efficient way to do this, I don't want to quote, and then send the data to pieces. I read somewhere that you can increase the size of the socket buffer, and this may help. Can anyone think of this. Any help is appreciated

+3
source share
6 answers

You should, and really should, be obsessed with sending data to pieces.

As explained in the Bay Network Guide:

"send() - , ! ., , , . , ".

, 1 , send() , , , (), , . , , , send() .

, 1 , , , 1 , 1, .

, send(), recv(). , , , , .

Beej send() recv() , . http://beej.us/guide/bgnet/output/print/bgnet_USLetter.pdf

+3

?

99% .

+1

Windows , , . , .

0

, ? "" .

, .

0

, Winsock. , , , .

, , , , . , , (64k ballpark), .

0

, ++:

#define DEFAULT_BUFLEN 1452    
int SendStr(const SOCKET &ConnectSocket, const std::string &str, int strlen){
        char sndbuf[DEFAULT_BUFLEN];
        int sndbuflen = DEFAULT_BUFLEN;
        int iResult;
        int count = 0;
        int len;
        while(count < strlen){
            len = min(strlen-count, sndbuflen);
            //void * memcpy ( void * destination, const void * source, size_t num );
            memcpy(sndbuf,str.data()+count,len);
            // Send a buffer
            iResult = send(ConnectSocket, sndbuf, len, 0);
            // iResult: Bytes sent
            if (iResult == SOCKET_ERROR){
                throw WSAGetLastError();
            }
            else{
                if(iResult > 0){
                    count+=iResult;
                }
                else{
                    break;
                }
            }
        }
        return count;
    }
0

Source: https://habr.com/ru/post/1703265/


All Articles