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

Author Topic: sf::Packet the packet data is mixed up  (Read 5552 times)

0 Members and 1 Guest are viewing this topic.

s1and1

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
sf::Packet the packet data is mixed up
« 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();
}
« Last Edit: December 30, 2021, 10:55:21 am by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: sf::Packet the packet data is mixed up
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

s1and1

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: sf::Packet the packet data is mixed up
« Reply #2 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

 

anything