SFML community forums

Help => Network => Topic started by: s1and1 on December 30, 2021, 09:35:21 am

Title: sf::Packet the packet data is mixed up
Post by: s1and1 on December 30, 2021, 09:35:21 am
Hello, I'm trying to create a thread that takes an instance of the sf::Packet class as an argument, but everything is mixed up there.


sf::UdpSocket sock;

void server(sf::Packet pack, sf::Address addr, sf::Packet packet){
int a;
pack >> a;
std::cout<<a;
}

int main(){
sf::Address addr;
sf::Packet packet;
unsigned short port;
sock.bind(19132);
sock.receive(packet, addr, port);
std::thread thr(server, packet, addr, port);
thr.detach();
}
Title: Re: sf::Packet the packet data is mixed up
Post by: eXpl0it3r on December 30, 2021, 10:57:10 am
You shouldn't really just detach a thread, otherwise your application will terminate independently of your thread. Instead join that thread at the end.

You need to be more specific that "mixed up", what exactly is the issue you're having?

For next time please make sure to pick the match subforum and use [code=cpp][/code] tags when posting code.
Title: Re: sf::Packet the packet data is mixed up
Post by: s1and1 on December 30, 2021, 07:48:18 pm
I'm going to make synchronization to a separate thread, but Dos attacks often occur, which leads to a stop