SFML community forums
Help => Network => Topic started by: kinglime on November 28, 2013, 05:37:08 am
-
I have my packets set up so that the first thing I send in them is a header. My headers are stored in an enum, like so:
enum networkHeaders {PlayerMove, ClientDisconnect, Test};
I can send the packet just fine, like so:
outgoingPacket << header
But I cannot receive the packet, like so:
incomingPacket >> header
Also this is my header variable:
networkHeaders header;
I would appreciate some help here, I tried searching the forums. Enums and networking are new concepts to me but I'm eager to learn. Thanks in advance.
-
Seconds later I believe I have found the solution to my mistake :)
I did the following:
int x;
incomingPacket >> x;
networkHeaders header;
header = (networkHeaders) x;
That seems to do the trick. I don't know if that is the best way to do this, if there is a better way please let me know. Thanks!
Edit: Is there some way to modify sf::Packet& operator >> to do this automatically?
-
You said "it does not work", but how exactly do you notcie that?
You shoulx use C++ casts, like static_cast<type>.
The issue here is, that C++ doesn't allow the implicit conversion from int to enum and it's nothing SFML cablln and should do against it. ;)
-
networkHeaders is a custom type defined by you, SFML knows nothing about it. So if you want operators << and >> that handle it correctly, you have to write them. See the tutorial for more details.