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 - Natulyre

Pages: [1]
1
Network / Re: sf::Socket::Partial status after TcpSocket::disconnect()
« on: August 05, 2016, 01:40:51 pm »
I found out the cause of my issue.

When I was testing, I packed up a standalone version of the client-side of my testing environment. Since my project is using dynamically linked libraries I logically had to add SFML's DLL files within my executable's folder.

I meant to try this standalone version on another computer but ended up testing it locally. That's when I noticed, that for the first time, I would receive a sf::Socket::Disconnected state.

I then had an epiphany. I never added any of SFML's DLL files within my projects folder even though I'm using dynamically linked libraries. I never got any missing DLL error so I hadn't even considered it, but Visual Studio's contained within its directory, a bunch of old DLL files from an outdated SFML version. Damn!

I'm now properly receiving a sf::Socket::Disconnected status upon either disconnecting the client or the server and I've learned a great lesson.

2
Hello,

I was messing around with TcpSockets after reading about them via Communicating with sockets, but I've ran into an issue. I'm struggling to figure out why it's happening so I'd very much appreciate any help I can get. It's probably a silly mistake.

I've set up a small testing environment for myself split in two solutions, one for the client and one for the server.

If I call TcpSocket::disconnect(), whether it be from the client's side or the server's; it will not result in the other side's socket status on TcpSocket::send([...]) or TcpSocket::receive([...]) to be sf::Socket::Disconnected. It'll always end up as sf::Socket::Partial, until I call disconnect from their side.

I was using this post from Laurent and this post from binary1248 as references points.

These aren't exactly the most recent posts and sf::Socket::Partial status has only been recently introduced with SFML 2.3, but I'd still expect the logic to be valid.

PS: I'm mostly curious in finding out why my issue is happening. I don't plan to do anything specific with this so I wouldn't consider"alternate" solutions (such as using packets or adding a heartbeat ping) to be of much interest or help.

Thanks

Server
#include <SFML\Graphics.hpp>
#include <SFML\Network.hpp>
#include <iostream>

sf::RenderWindow* serverWindow;
sf::TcpListener* listener;
sf::TcpSocket* client;

bool serverIsOpen = false;

void CloseServer()
{
        std::cout << "---" << __FUNCTION__ << "---" << std::endl;

        client->disconnect();
        listener->close();
        serverIsOpen = false;

        std::cout << "---------------" << std::endl;
}

void OpenServer()
{
        std::cout << "---" << __FUNCTION__ << "---" << std::endl;

        serverIsOpen = true;

        if (listener->listen(41852) != sf::Socket::Done)
        {
                std::cout << "Listen - Error" << std::endl;
        }
        else
        {
                std::cout << "Listen - OK" << std::endl;
        }

        if (listener->accept(*client) != sf::Socket::Done)
        {
                std::cout << "Accept - Error" << std::endl;
        }
        else
        {
                std::cout << "Accept - Ok" << std::endl;
        }

        std::cout << "---------------" << std::endl;
}

void ReceiveData()
{
        std::cout << "---" << __FUNCTION__ << "---" << std::endl;

        char data[5];
        std::size_t received;
        sf::Socket::Status status = client->receive(&data, 5, received);

        std::cout << status << "- ";

        switch (status)
        {
        case (sf::Socket::Status::Disconnected) :
                std::cout << "Disconnected" << std::endl;
                break;

        case (sf::Socket::Status::Done) :
                std::cout << "Success" << std::endl;
                break;

        case (sf::Socket::Status::Error) :
        case (sf::Socket::Status::NotReady) :
        case (sf::Socket::Status::Partial) :
        default:
                std::cout << "Error" << std::endl;
                break;
        }

        std::cout << "---------------" << std::endl;
}

void SendData()
{
        std::cout << "---" << __FUNCTION__ << "---" << std::endl;

        char data[5] = "TEST";

        sf::Socket::Status status = client->send(data, 5);
        std::cout << status << "- ";

        switch (status)
        {
        case (sf::Socket::Status::Disconnected) :
                std::cout << "Disconnected" << std::endl;
                break;

        case (sf::Socket::Status::Done) :
                std::cout << "Success" << std::endl;
                break;

        case (sf::Socket::Status::Error) :
        case (sf::Socket::Status::NotReady) :
        case (sf::Socket::Status::Partial) :
        default:
                std::cout << "Error" << std::endl;
                break;
        }

        std::cout << "---------------" << std::endl;
}

int main()
{
        serverWindow = new sf::RenderWindow(sf::VideoMode(400, 400), "Server Window");

        listener = new sf::TcpListener;
        client = new sf::TcpSocket;

        client->setBlocking(true);

        while (serverWindow != nullptr && serverWindow->isOpen())
        {
                sf::Event event;
                while (serverWindow->pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                        {
                                serverWindow->close();
                        }
                        else if (event.type == sf::Event::KeyPressed)
                        {
                                switch (event.key.code)
                                {
                                case (sf::Keyboard::O) :
                                        if (!serverIsOpen)
                                        {
                                                OpenServer();
                                        }
                                        break;

                                case (sf::Keyboard::C) :
                                        if (serverIsOpen)
                                        {
                                                CloseServer();
                                        }
                                        break;

                                case (sf::Keyboard::R) :
                                        ReceiveData();
                                        break;

                                case (sf::Keyboard::S) :
                                        SendData();
                                        break;

                                default:
                                        break;
                                }
                        }
                }

                serverWindow->clear();
                serverWindow->display();
        }

        return 0;
}
 

Client
#include <SFML\Graphics.hpp>
#include <SFML\Network.hpp>
#include <iostream>

sf::RenderWindow* clientWindow;
sf::TcpSocket* socket;

void Connect()
{
        std::cout << "---" << __FUNCTION__ << "---" << std::endl;

        sf::Socket::Status status = socket->connect("127.0.0.1", 41852);


        if (status != sf::Socket::Done)
        {
                std::cout << "Client connection attempt failed." << std::endl;
        }
        else
        {
                std::cout << "Client connection attempt succeeded." << std::endl;
        }

        std::cout << "---------------" << std::endl;
}

void Disconnect()
{
        std::cout << "---" << __FUNCTION__ << "---" << std::endl;

        socket->disconnect();

        std::cout << "---------------" << std::endl;
}

void ReceiveData()
{
        std::cout << "---" << __FUNCTION__ << "---" << std::endl;

        char data[5];
        std::size_t received;
        sf::Socket::Status status = socket->receive(&data, 5, received);

        std::cout << status << "- ";

        switch (status)
        {
        case (sf::Socket::Status::Disconnected) :
                std::cout << "Disconnected" << std::endl;
                break;

        case (sf::Socket::Status::Done) :
                std::cout << "Success" << std::endl;
                break;

        case (sf::Socket::Status::Error) :
        case (sf::Socket::Status::NotReady) :
        case (sf::Socket::Status::Partial) :
        default:
                std::cout << "Error" << std::endl;
                break;
        }

        std::cout << "---------------" << std::endl;
}

void SendData()
{
        std::cout << "---" << __FUNCTION__ << "---" << std::endl;

        char data[5] = "TEST";

        sf::Socket::Status status = socket->send(data, 5);
        std::cout << status << "- ";

        switch (status)
        {
        case (sf::Socket::Status::Disconnected) :
                std::cout << "Disconnected" << std::endl;
                break;

        case (sf::Socket::Status::Done) :
                std::cout << "Success" << std::endl;
                break;

        case (sf::Socket::Status::Error) :
        case (sf::Socket::Status::NotReady) :
        case (sf::Socket::Status::Partial) :
        default:
                std::cout << "Error" << std::endl;
                break;
        }

        std::cout << "---------------" << std::endl;
}

int main()
{

        clientWindow = new sf::RenderWindow(sf::VideoMode(400, 400), "Client Window");
        socket = new sf::TcpSocket();

        socket->setBlocking(true);

        while (clientWindow != nullptr && clientWindow->isOpen())
        {
                sf::Event event;

                while (clientWindow->pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                        {
                                clientWindow->close();
                        }
                        else if (event.type == sf::Event::KeyPressed)
                        {
                                switch (event.key.code)
                                {
                                case (sf::Keyboard::C) :
                                        Connect();
                                        break;

                                case (sf::Keyboard::D) :
                                        Disconnect();
                                        break;

                                case (sf::Keyboard::R) :
                                        ReceiveData();
                                        break;

                                case (sf::Keyboard::S) :
                                        SendData();
                                        break;

                                default:
                                        break;
                                }
                        }
                }

                clientWindow->clear();
                clientWindow->display();
        }

        return 0;
}
 

3
General / Color Incrementing
« on: March 29, 2011, 10:57:47 pm »
Yikes, Thanks for the help!

I just found out my oh so stupid mistake. I was trying to skip a few steps while trying to change the R component. It all makes sense to me now. Yay =)

4
General / Color Incrementing
« on: March 29, 2011, 10:50:05 pm »
Quote from: "danman"
I think you want to interpolate (increment during a fixed time, if my english is bad) ?


My code example isn't really useful at all my bad, I understand what you're trying to explain though. Don't worry =)

Code: [Select]

Snip

Quote from: "danman"

or make an object to interpolate values.

I think i've made a mistake, it's 22:47 and never used it, so be careful and rewrite it ^^ .


That seems quite interesting, I'll give it a try

5
General / Color Incrementing
« on: March 29, 2011, 10:48:11 pm »
Quote from: "Nexus"

2. Change its red value


That's actually what I'm having a hard time with.

6
General / Color Incrementing
« on: March 29, 2011, 10:22:05 pm »
Hi there, I'm kind of puzzled. I've been trying to Increment a sprite's specific color (R, G, B) with an input. Is there anyway to do so?

Basically I'd want the sprite's color to go through the following change (R+1, G, B).

I looked at the docs and they seem to be public data members of the color class but Color is a private member of drawables, there has to be a way to do this somehow...

Code: [Select]

if (App.GetInput().IsKeyDown(sf::Key::Down))  Sprite.SetColor(Iamconfused);


Thanks in advance.

Pages: [1]