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

Author Topic: Shifting sf::Packet into another sf::Packet  (Read 2961 times)

0 Members and 1 Guest are viewing this topic.

FleshyOverlord

  • Newbie
  • *
  • Posts: 22
    • View Profile
Shifting sf::Packet into another sf::Packet
« on: April 16, 2019, 05:57:49 pm »
Is there any way to shift a sf::Packet into anoter sf::Packet as seen below(figure1)? I am trying to setup a function that takes a sf::Packet as an arguement, stamps a name on the packet, and then sends it to a client. The problem now is that all that data in the data variable(figure 2) is lost when the data variable is shifted into the newPacket variable.

sf::Packet data;
std::string name = "Bob";
int age;
data << bob <<age;

sf::Packet FinalPacket;
std::string PacketType = "Name";
FinalPacket << PacketType << data;
 



figure 2
bool SFMLNetwork::sendUDP(sf::Packet data, std::string Type, sf::IpAddress receiver, unsigned short rcvPort)
{
        sf::Packet newPacket;
// not sure if data can be shifted into newPacket
        newPacket << Type << data;
        if (UdpSocket.send(newPacket, receiver, rcvPort) == sf::Socket::Status::Done) {
                return true;
        }
        else {
                return false;
        }
}

 
« Last Edit: April 16, 2019, 10:09:57 pm by FleshyOverlord »