pocoproject / poco

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
https://pocoproject.org
Other
8.05k stars 2.11k forks source link

SocketStream messages doesn't send, and send after close socket. #4526

Closed iliyafaramarzi closed 2 months ago

iliyafaramarzi commented 2 months ago

i'm working on poco library and i want to create a TCP based program something like chatroom. I have a Server and a Client. when i use SocketStream to send messages to the server it doesn't work at the moment and send messages after the socket is closed(flush() doesn't work). i test socket.shutdownSend() it work but just for a message and after that close the socket. what should i do? is it better to use sendBytes and recieveBytes or no? my client Code: `int main() { string message; StreamSocket socket; SocketAddress address("127.0.0.1", 8080);

socket.connect(address);

SocketOutputStream stream(socket);

while(true){
    getline(cin, message);

    if(message != "end"){
        stream << message;
        stream.flush();
    }else{
        break;
    }
}

return 0;

}`

mt server Code: `int main() { try { ServerSocket serverSocket(8080); cout << "Server started" << endl;

    while (true) {
        StreamSocket clientSocket = serverSocket.acceptConnection();
        SocketStream stream(clientSocket);

        string message;
        StreamCopier::copyToString(stream, message);
        cout << "Client says: " << message << endl;
    }
} catch (Exception& ex) {
    cerr << ex.displayText() << endl;
}

return 0;

}`