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

Author Topic: sf::Packet and single char  (Read 4872 times)

0 Members and 1 Guest are viewing this topic.

l0ud

  • Newbie
  • *
  • Posts: 23
    • View Profile
sf::Packet and single char
« on: August 31, 2009, 08:00:07 pm »
Hi

Is it possible, to send and receive single char via sf::packet? I'm trying to do this with simple code:

Code: [Select]

sf::Packet packet;
char test = 0x01;
packet << test;
//sending packet



Code: [Select]

sf::Packet packet;
//receiving packet
char test;
packet >> test;
if (test == 0x01) std::cout << "Correct";
else std::cout << "Wrong" << (int)test;


...but it's not work: test is alyways 0.

Is there any solution for this problem?
Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Packet and single char
« Reply #1 on: August 31, 2009, 08:41:54 pm »
If you put other types of data (float, string, ...), does it work?
Laurent Gomila - SFML developer

l0ud

  • Newbie
  • *
  • Posts: 23
    • View Profile
sf::Packet and single char
« Reply #2 on: August 31, 2009, 09:42:08 pm »
Sending other types of data works, but sending char with (for example) string, doesn't work...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Packet and single char
« Reply #3 on: August 31, 2009, 10:44:21 pm »
What about sf::Int8?
Laurent Gomila - SFML developer

l0ud

  • Newbie
  • *
  • Posts: 23
    • View Profile
sf::Packet and single char
« Reply #4 on: September 01, 2009, 11:29:59 am »
It works correctly, so my problem is solved, thanks. :)
Anyway, it's nice to know, why the char type didn't work...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Packet and single char
« Reply #5 on: September 01, 2009, 11:54:56 am »
That's weird because sf::Int8 is a typedef on char.
Laurent Gomila - SFML developer

l0ud

  • Newbie
  • *
  • Posts: 23
    • View Profile
sf::Packet and single char
« Reply #6 on: September 01, 2009, 12:06:21 pm »
Oops, that's because I used sf::Uint8 instead of sf::Int8. So, unsigned char works, signed doesn't :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Packet and single char
« Reply #7 on: September 04, 2009, 03:09:35 pm »
I did some tests, and it works perfectly if you use a sf::Int8 on each side.

It doesn't work with char (which is ok), but the compiler informs you with a warning if it's proplery configured.
Laurent Gomila - SFML developer

 

anything