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

Author Topic: [Solved] UDP receive method not compiling  (Read 513 times)

0 Members and 1 Guest are viewing this topic.

Guido_Ion

  • Newbie
  • *
  • Posts: 46
    • View Profile
    • Flow Football development
[Solved] UDP receive method not compiling
« on: May 06, 2025, 12:35:22 am »
I'm following the tutorial Communicating with sockets for SFML 3.0 and I get this compiler error on the receive method

"no instance of overloaded function matches the argument list"

this is part of my code
Code: [Select]
#define IP 191, 168, 1, 50
#define PORT 54000
...
    sf::UdpSocket socket;
    sf::IpAddress sender(IP); // I had to add the IP here because it gave me an error if I left it like in the tutorial

    std::uint16_t x;
    std::string s;
    double d;
    sf::Packet packet;
    packet >> x >> s >> d;

    ...

    if (socket.receive(packet, sender, PORT) != sf::Socket::Status::Done)
    {
        //  error
    }

It won't tell me which is the incorrect argument, maybe it's the sender that is now sf::optional?
Was the tutorial 3.0 for networking not updated from 2.5?

I have some years of experience in C++ and SFML but I'm new to networking.
« Last Edit: May 06, 2025, 11:09:23 pm by Guido_Ion »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
    • development blog
    • Email
Re: UDP receive method not compiling
« Reply #1 on: May 06, 2025, 07:59:52 am »
Looks like the tutorial wasn't properly updated.

You need to use a std::optional<sf::IpAddress> for the sender param.
See the example in the documentation: https://www.sfml-dev.org/documentation/3.0.1/classsf_1_1UdpSocket.html#details
Official FAQ: https://www.sfml-dev.org/faq/
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Guido_Ion

  • Newbie
  • *
  • Posts: 46
    • View Profile
    • Flow Football development
Re: UDP receive method not compiling
« Reply #2 on: May 06, 2025, 11:08:27 pm »
That solved it, also the PORT was assumed int because I used #define, it should be an unsigned short so I created a variable, thanks!