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

Author Topic: Changing only the header of sf::Packet between sending it to different clients?  (Read 2149 times)

0 Members and 1 Guest are viewing this topic.

spacebasics

  • Newbie
  • *
  • Posts: 2
    • View Profile
Say I have 5 clients that I want to send the same game 'snapshot' to, but I want them to have unique headers. I don't want to have to re-build the packet between each send, but I can't think of any way to do this without re-building the packet from scratch between each socket.send(packet, connection[j].ip, connection[j].port).

If my question still isn't clear here is an example:

Msg for client 1:
12
6
4
5
7
Msg for client 2:
18
3
4
5
7
Msg for client 3:
15
1
4
5
7
Msg for client 4:
0
0
4
5
7
Msg for client 5:
3
5
4
5
7

Each client is getting the same bottom 3 numbers, but they have unique numbers in the top two. What I am doing now is building the packet for c1, sending to c1, clear packet, build packet for c2, send to c2, clear, build packet for c3, etc.

This seems like a waste.

I could make do with moving the 'unique' fields to the bottom of the packet if that's the only way. Maybe I could do this by sending the shared version of the packet to a function with func(sf::Packet packet) signature forcing a copy?

Thanks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
There's no direct solution for this in SFML, I'm afraid you'll have to investigate and find the workaround that works best for you.
Laurent Gomila - SFML developer

spacebasics

  • Newbie
  • *
  • Posts: 2
    • View Profile
Okay thank you. It seems as though my best bet is to build the shared portion of the packet first then pass that into a function as value (not reference) so it's copied and then in that function add the unique pieces before sending it. This results in part of the 'header' being at the end of the packet, but has the functionality I was looking for.