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

Author Topic: Handling array's with sf::Packet?  (Read 3264 times)

0 Members and 1 Guest are viewing this topic.

Otoris

  • Newbie
  • *
  • Posts: 7
    • View Profile
Handling array's with sf::Packet?
« on: January 21, 2013, 11:55:58 am »

Client receive code:
Code: [Select]
    sf::Packet receivePacket;
    sf::IpAddress sender;
    unsigned short senderPort;

    if (socket.receive(receivePacket, sender, senderPort) != sf::Socket::Done)
        return;
    sf::Vector2i lVec[20];
    int lRot[20];
    sf::IpAddress lIP[20];
    if (receivePacket >> lVec >> lRot >> lIP);
        nextUpdateGame(lVec, lRot, lIP);

Error:
error: no match for 'operator>>' in 'receivePacket >> lVec'

Is this even possible? I'm banging my head against the wall trying to send 3 arrays from a SFML server:
Server code:
Code: [Select]
    sf::Packet net_send;
    net_send << pListVec << pListRot << pListIP;
    if (socket.send(net_send, pListIP[i], port) != sf::Socket::Done)
        return;

pListVec is a sf::Vector2i array.
pListRot is int array.
pListIP is sf::IpAddress array.

The server side of things is compiling properly but I'm having issues working out getting the clients to unpack these packets for use...

Any ideas?

Thanks in advance! ^^

As a note: This is all UDP networking. If you wish to see the rest for perspective, I'd be happy to upload but be warned... It isn't pretty as this is a 48h game jam project...



« Last Edit: January 21, 2013, 12:15:02 pm by Otoris »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Handling array's with sf::Packet?
« Reply #1 on: January 21, 2013, 12:14:18 pm »
There's no overload for arrays, you have to insert all elements one by one.
Laurent Gomila - SFML developer

Otoris

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Handling array's with sf::Packet?
« Reply #2 on: January 21, 2013, 12:17:24 pm »
There's no overload for arrays, you have to insert all elements one by one.

The issue arises with the fact that the client doesn't know how many entries are in the array before it receives it. But I think I see what you mean? It be best to send several different vectors and such one at a time instead of grouped with sf::Packet?

Also the sorting/handling of packets gets mixed up as a packet is a packet and the client/server doesn't care which one it gets.
« Last Edit: January 21, 2013, 12:20:33 pm by Otoris »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Handling array's with sf::Packet?
« Reply #3 on: January 21, 2013, 12:20:58 pm »
You must encode how many elements you send in the packet, if this number is not known.
Laurent Gomila - SFML developer

Otoris

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Handling array's with sf::Packet?
« Reply #4 on: January 21, 2013, 12:34:24 pm »
Just as a quick test I tried overloading the first two elements instead of the whole array:
Code: [Select]
receivePacket >> lVec[0] >> lVec[1]
This gives the same error:
no match for 'operator>>' in 'receivePacket >> lVec[0]'

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Handling array's with sf::Packet?
« Reply #5 on: January 22, 2013, 08:37:21 am »
There is no overload for sf:Vector2i ;)

Please read the documentation.
Laurent Gomila - SFML developer

 

anything