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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Alidaco

Pages: [1]
1
My previous question was very vague. After doing more digging into my problem, I realized that in non-blocking mode, after many successive packet sendings, the packets were no longer sent and the send function began to return status "NotReady". I thought that I might be "overloading" the socket by doing so much so quickly, so I added some code to delay for 1 second after I got the NotReady status to let it "catch up". Sorry if that course of action seems stupid, but I'm trying my best to understand what's going on here. Regardless, that didn't help, and after the first failure, ever successive call also returns "NotReady". What do you guys think would cause a socket to repeatedly say that it's not ready after sending quite a few packets correctly in quick succession? I'm totally baffled! I hope one of you can help. I look forward to your responses, and thank you for reading!

2
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());
    }
}

3
I think I'll just make a wrapper class for it that will handle the allocation and deletion with constructors and destructors. Thanks for your help! I just wanted to make sure that I wasn't missing the obvious.

4
So I should make a vector of smart pointers. Each smart pointer contains a normal pointer to a sf::TcpSocket which is initialized with a call to "new". Then I use the objects through the mart pointers and the sf::TcpSockets are deleted automatically when I delete a smart pointer off of the vector? I've never used smart pointers before so I just want to make sure that I'm understanding everything properly. Thanks a lot for your help!

5
Like the title says, I'm 100% sure that this is a stupid question, but I have been unable to figure it out for some reason. How can I store the sf::TcpSocket? The Tutorial mentions that the selector doesn't store it, so I should look into using a vector, but I can't put it into a vector because it's non-copyable. I can't just make one and leave it alone, because it would go out of scope. Do I have to manage it manually with "new" and "delete" and my own data types? Surely there's a better way, right? What am I missing here? Thanks guys, I look forward to your answers.

Pages: [1]
anything