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

Author Topic: Not reading third string in packet  (Read 5832 times)

0 Members and 1 Guest are viewing this topic.

Ninjinka

  • Newbie
  • *
  • Posts: 2
    • View Profile
Not reading third string in packet
« 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:

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?

Ninjinka

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Not reading third string in packet
« Reply #1 on: December 05, 2020, 07:53:35 am »
Solved, I accidentally was sending the whole player object instead of just the name

 

anything