SFML community forums

Help => Network => Topic started by: Ninjinka on December 05, 2020, 07:45:39 am

Title: Not reading third string in packet
Post by: Ninjinka on December 05, 2020, 07:45:39 am
I send a packet like this:

void unencryptedMessage(sf::IpAddress recipient, unsigned short port, characterSprite player) {
    sf::Packet packet;
    string packetType = "message";
    packet << packetType << player << player.message;
    if (clientSocket.send(packet, recipient, port) != sf::Socket::Done) {
        cout << "Did not send data." << endl;
    }
    return;
}
 

I then receive the packet like this:
string packetType;
packet >> packetType;
if (packetType == "message"){
            string message;
            packet >> playerName >> message;
            playerMessages[playerName] = message;
            cout << playerName << ": " << message << endl;
        }
 

Let's say the playerName is "Ninjinka" and the message is "Test."

Here is the packet that the server receives: (https://i.imgur.com/mnaKrMH.png)

As you can see, the message doesn't appear to read anything. It only appears to read in the first 27 bytes, whereas the message starts on the 35th byte. Any ideas as to why it's doing this?
Title: Re: Not reading third string in packet
Post by: Ninjinka on December 05, 2020, 07:53:35 am
Solved, I accidentally was sending the whole player object instead of just the name