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 - Martin Lefevre

Pages: [1]
1
Graphics / Cannot call draw() from constant RenderTarget object.
« on: April 14, 2020, 05:49:02 pm »
Hi,
I made a function that is supposed to draw a text on a RenderTarget. But I an error message saying that "No instance of overloaded function could be found.". Here is my function:
void DrawStringInBox(const sf::RenderTarget &xindox, const std::string& String, const sf::Font& font) {
        sf::Text text(String, font);
        xindox.draw(text);
}

But, it works fine when I remove the const before the RenderTarget:
void DrawStringInBox(sf::RenderTarget &xindox, const std::string& String, const sf::Font& font) {
        sf::Text text(String, font);
        xindox.draw(text);
}

Why? Isn't draw() a const function? And if it isn't, why wouldn't it be?

2
Network / Re: Cannot read from Packet.
« on: April 03, 2020, 03:14:51 pm »
Ok, I found the problem: my Connect function sends bytes of data to the other peer, to establish the connection. But if I don't call receive to "clean" the port after that, when I will call receive to collect useful data (such as this packet), I'll collect the random byte instead, thus causing issues such as this one.

3
Network / Cannot read from Packet.
« on: April 02, 2020, 07:06:09 pm »
Hi,

While reading the tutorial about packets, I tried to do my own project to test it. So, I made a peer-to-peer connection between two computers (it works! ^^), and I sent a packet from one to the other... The problem is when I try to read from the packet: the >> operator always returns false.
Here is the code:

On the sender's side:

#include <sfml/network.hpp>

sf::UdpSocket UdpS;

namespace Contact
{
         sf::IpAddress Ip;
        unsigned short Port;
};

int main() {
        UdpS.setBlocking(false);

        //Establishes P2P connection,
       //and finds the other contact's IP and port.
       //Also binds UdpS.
      //Returns true here.
        if (!Connect()) {
                std::cout << "Connection error." << std::endl;
                return 1;
        }
        std::cout << "Connected." << std::endl;

        sf::Uint16 u = 5;
        sf::Packet pack; pack << u;
        if (UdpS.send(pack, Contact::Ip, Contact::Port) != sf::Socket::Done) {
                std::cout << "Failure." << std::endl;
        }
        std::cout << "Sent" << std::endl; //Sent is printed, thus the packet is sent correctly.
}



And on the recipient's side:

#include <sfml/network.hpp>

sf::UdpSocket UdpS;

namespace Contact
{
         sf::IpAddress Ip;
        unsigned short Port;
};

int main() {
        UdpS.setBlocking(false);
        //Establishes P2P connection,
       //and finds the other contact's IP and port.
       //Also binds UdpS.
      //Returns true here.
        if (!Connect()) {
                std::cout << "Connection error." << std::endl;
                return 1;
        }
        std::cout << "Connected.   " << std::endl;

        UdpS.setBlocking(true);
        sf::Packet pack;
        if (UdpS.receive(pack, Contact::Ip, Contact::Port) != sf::Socket::Done) { return 1; }
       
        sf::Uint16 i;
        if (!(pack >> i)) { std::cout << "Reading failed." << std::endl; return 1; } //Reading failed is printed.
       
}

4
I got the same problem, it is surely the NAT: it blocks every connection from the outside world that seems unfamiliar. You're trying to send data to the client but the client's NAT sees it and says "I don't know you! Go away!". And your data just gets rejected. To avoid such rudeness, you should use the UDP/TCP hole punching methods, or forward ports of your server.

To make it simple, hole punching is sending something to the other contact, so that your NAT knows that you were trying to make a connection with this contact. Then, the other computer can send you data, and your NAT will say "Hey, that's the guy you were trying to connect to! You can pass." and the data will reach your computer. The problem with this method is that both computers have to know each other's address and port.

On the other hand, we have port forwarding: port forwarding is allowing connections on a specific port of your computer. I don't know how to do this though, but it should not be too complicated. Forwarding ports on the server's side is enough to establish a connection. The only requirement to this method is the user having the address of the server , and the port that is forwarded. Therefore, the client just has to try to connect to the server, the server's NAT will say "The port is forwarded, you're lucky." and will do nothing. Then, with the new connection formed between the client and the server, the server knows the address of the client, and can send data without trouble (because the client has already sent data to the server, so the client's NAT will be cool on the data the server is going to send).

Edit: oooops, I didn't see that you already knew port forwarding... My bad. Well, I'll keep this comment in case if someone didn't know that...

If you did not understand this book, feel free to insult me in a polite way.

5
Oh, that was simple... thanks!

6
 Hi,

I was trying to compile a static version of SFML with CMake for Visual Studio 2019, I think I followed the tutorial (https://www.sfml-dev.org/tutorials/2.5/compile-with-cmake.php) correctly. The problem is that once I open the CMake generated solution to finally build SFML, I see that I cannot switch the solution configuration to x86, thus preventing me to build SFML in 32-bits.

Here are all the steps I did to compile SFML with CMake:

Firstly, I downloaded the SFML source code,
then, I opened CMake, chose the SFML file as source code and a build folder to put built files into.
Then, I clicked on configure, chose Visual studio 16 2019 as generator, and clicked on finish.
Once the configuring done, I unchecked BUILD_SHARED_LIBS, checked SFML_USE_STATIC_STD_LIBS, clicked on configure, then generate. Once everything is done, I clicked on the Open_Project button which opens the generated Visual Studio solution.

And there is the issue: I cannot switch the project's configuration to something else than x64...

What did I do wrong?

Pages: [1]