Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [BAD QUESTION] Sending packets over a TcpSocket fails if not in blocking mode.  (Read 2190 times)

0 Members and 3 Guests are viewing this topic.

Alidaco

  • Newbie
  • *
  • Posts: 5
    • View Profile
I'm not sure if this is against forum rules, but I've realized that I've done a poor job of providing information about my problem in this thread. I've started a new one to try to better organize my thoughts without forcing you guys to read code snippets. I'm going to leave this one open until the problem is solved just in case the code snippets will help to solve the problem.

I have the sending socket set to non blocking mode because I have a loop running and I'll just handle the sending as the program loops. The issue happens when I try to send something every loop. The sending works flawlessly when I send something every 10,000th loop (just adding time between sending data). Is this to be expected? Included below is the code that I'm using. The first snippet sends every loop and fails early on (almost always the 4th send attempt), and the second snippet runs forever, flawlessly while sending data every 10,000th loop.

Code: [Select]
int basicClient()
{
    sf::TcpSocket client;
    client.setBlocking(false);

    while(client.connect("68.59.50.177", 5100) != sf::Socket::Done)
    {
        std::cout << "Client connecting to server" << std::endl;
    }
    std::cout << "Connection Successful" << std::endl;

    std::stringstream stringConverter;
    for(int counter = 0; true; counter ++)
    {
        std::string messageString;
        sf::Packet message;

        stringConverter << counter;
        messageString = stringConverter.str();
        message << messageString;
        std::cout << messageString << std::endl;

        if(client.send(message) != sf::Socket::Done)
            return 1;
           
        stringConverter.str(std::string());
    }
}

Code: [Select]
int basicClient()
{
    sf::TcpSocket client;
    client.setBlocking(false);

    while(client.connect("68.59.50.177", 5100) != sf::Socket::Done)
    {
        std::cout << "Client connecting to server" << std::endl;
    }
    std::cout << "Connection Successful" << std::endl;

    std::stringstream stringConverter;
    for(int counter = 0; true; counter ++)
    {
        std::string messageString;
        sf::Packet message;

        stringConverter << counter;
        messageString = stringConverter.str();
        message << messageString;
        std::cout << messageString << std::endl;

        if(counter%10000 == 0)
            if(client.send(message) != sf::Socket::Done)
                return 1;
        stringConverter.str(std::string());
    }
}
« Last Edit: July 25, 2013, 12:13:40 am by Alidaco »

 

anything