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

Author Topic: Sending enum through a packet  (Read 2315 times)

0 Members and 1 Guest are viewing this topic.

Strikerklm96

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Sending enum through a packet
« on: January 24, 2015, 07:58:07 am »
Is it safe to do this?
Packet packet;
packet << static_cast<int32_t>(Protocol::Control);//Protocol is an enum class
send(packet);
I am trying to send different types of commands through the network, and i'm not sure if this is reliable.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Sending enum through a packet
« Reply #1 on: January 24, 2015, 08:21:33 am »
Why wouldn't it be safe?
Laurent Gomila - SFML developer

Strikerklm96

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: Sending enum through a packet
« Reply #2 on: January 24, 2015, 04:22:05 pm »
I thought I read somewhere that enums aren't necessarily always the same type, which made me worried that they might not cast to the same value. I was having a few problems and just wanted to eliminate that as a possibility. I think I found my actual problem though.

And I thought the following question didn't deserve a new thread: It makes sense use both UDP and TCP in the same program right? I want TCP for data that can't get lost or duplicated ect. Do I need to bind each socket to different ports so my program actually uses two ports?
« Last Edit: January 24, 2015, 04:35:49 pm by Strikerklm96 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Sending enum through a packet
« Reply #3 on: January 24, 2015, 04:47:36 pm »
Quote
I thought I read somewhere that enums aren't necessarily always the same type
Yes, but you can cast them to any interger type (that is large enough to contain all the enum constants). So there's no problem.

Quote
It makes sense use both UDP and TCP in the same program right?
Yes.

Quote
Do I need to bind each socket to different ports so my program actually uses two ports?
Yes.
Laurent Gomila - SFML developer

 

anything