SFML community forums
Help => Network => Topic started by: Manux on March 12, 2010, 12:52:20 am
-
Hello,
I've just stumbled upon a really weird thing, it's either a bug or a misunderstanding from me.
If I put << an sf::Uint8 into a packet, and then >> it out by using a char instead, not only will it not work, but it will affect the rest of the packet!
(I use v1.5 too, maybe I should switch?)
here is the minimal code:
sf::Packet p;
std::string s1 = "Hello!";
std::string s2;
int i1 = 1;
int i2 = 5;
int i3,i4;
//DEFAULT_HEAD is an sf::Uint16 and NPC_DIALOG is a sf::Uint8
p<<DEFAULT_HEAD<<GEVENT_NPC_DIALOG<<i1<<i2<<s1;
unsigned short h;
//change the type to Uint8 or unsigned char and it will change the output!
//sf::Uint8 t;
char t;
p>>h>>t>>i3>>i4>>s1;
printf("%d %d %d %d %s\n",h,t,i3,i4,s1.c_str());
Output with char t:
35812 0 117440512 16777216
Output with uint8
35812 7 1 5 Hello!
(the proper output)
-
Hi
There is no operator >> for the char type, your compiler should output an error with your code (mine does).
sf::Packet handles only fixed-size types (sf::Int8, sf::Uint16, ...). Native types are not safe to send through the network and thus are not directly supported.