POCO c++ sendbyte vs write (TCP/IP)

47 Views Asked by At

This is a code to send a random cv::Mat data through tcp/ip using POCO c++ :

try
{
    SocketAddress sa("127.0.0.1", 12345); // create a socket address for the server
    StreamSocket ss(sa); // create a stream socket for the server connection
    SocketStream str(ss); // create a socket stream for the server connection
    string message;
    Mat image(512, 512, CV_8UC1);
    

    getline(str, message); // read the server's message
    cout << "Received message from server: " << message << endl; // print the server's message

    if (!image.empty()) {
    
        vector<uchar> buffer;
        randu(image, Scalar::all(0), Scalar::all(255));
        imencode(".jpg", image, buffer);
    
        // send the byte array over the socket
        str.write((const char*)buffer.data(), buffer.size());

    }
       
}
catch (exception& e)
{
    cerr << e.what() << endl;
}

My question is about the str.write((const char*)buffer.data(), buffer.size());

Does it send all data or should I loop over the buffer like when using sendbyte ? I couldn't find any documentation about the difference.

0

There are 0 best solutions below