SFML community forums

Help => Network => Topic started by: fr1ar on May 14, 2014, 10:32:07 am

Title: const qualifier in send() function
Post by: fr1ar on May 14, 2014, 10:32:07 am
Is it possible to make first argument type const Packet& in future releases?
It doesn't look like it can be modified.

Socket::Status UdpSocket::send(Packet& packet, const IpAddress& remoteAddress, unsigned short remotePort)
Title: Re: const qualifier in send() function
Post by: Nexus on May 14, 2014, 10:34:35 am
It can, because of onSend() and onReceive().

But I agree that this is not a very beautiful limitation, especially since these methods are not used in the very most cases. Maybe in the future we can find a design that works without inheritance.
Title: Re: const qualifier in send() function
Post by: fr1ar on May 14, 2014, 10:51:49 am
Ok, it's not a big problem, my workaround works fine :)

void MySocket::send(const Address& address, const sf::Packet& packet)
{
        _socket.send(packet.getData(), packet.getDataSize(), address._ip, address._port);
}
Title: Re: const qualifier in send() function
Post by: Laurent on May 14, 2014, 11:01:52 am
This is not how a packet is sent internally. You may end up with problems if you use this code.