Question

What is getting written to the socket when I write an ENUM reference (below)? I have something captured in whireshark but it does not resemble the ENUM name "JOIN" .. it is not the same length either. The server somehow understands that this code sent the JOIN enum.

#include <sstream>
#include <iostream>

... WriteToSocket( SOCKET hSocket, char *buf, int iCount)
  send(hSocket, buf, iCount, 0);


enum { JOIN, ...};
m_Command = JOIN;
WriteToSocket (hSocket, (char *)&m_Command, sizeof(m_Command));

I hope I included enough info and include statements ...

Was it helpful?

Solution

An integral value is begin written. The size of the varaible can vary. In your case the size might be anything between either a 1-byte zero, up to an int-sized zero.

To see exactly what is being written, add this code:

std::cout << "Size: " << sizeof(m_Command) << " Value: " << (int)m_Command << "\n";

OTHER TIPS

If I understood correctly, you assume "JOIN" is transferred over network as a string. This is not correct. JOIN is an alias for an integer value (0 if it is the first member of enumeration). That integer value is transferred over the network, the server knows that; that particular integer value is an alias for "JOIN". Thats why your server works as expected.
Also you cannot see "JOIN" as a string in your wireshark logs, but the integer value which is alias of the "JOIN".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top