cpp_sockets icon indicating copy to clipboard operation
cpp_sockets copied to clipboard

TCP client unable to send multiple messages in a loop

Open Slluxx opened this issue 3 years ago • 0 comments

    const int invalid_protocol_return = 1;
    const int invalid_sockettype_return = 2;
    const int udp_protocol = 1;
    const int tcp_protocol = 2;
    const int client_socket = 1;
    const int server_socket = 2;

    u_short socket_port = 5000;
    std::string destination_ip = "192.168.2.182";

    TCPClient client(socket_port, destination_ip);
    int connection_status = client.make_connection();
    // Return if there is an issue binding
    if (connection_status)
    {
        return connection_status;
    }
    else
    {
        while (true)
        {
            client.send_message("Testmessage\n");
            client.send_message("Testmessage2\n");
            svcSleepThread(1000000000ull); // 5s
        }
    }

this code sends Testmessage but not Testmessage2, nor does it loop. it looks like it just stops executing.

EDIT: figured out why.

if (recv(m_socket, server_reply, 2000, 0) == SOCKET_ERROR)

blocks code execution untill something is recieved, even tho i never wanted to recieve anything.

Slluxx avatar Oct 24 '22 15:10 Slluxx