SFML community forums
Help => Network => Topic started by: e_barroga on August 13, 2010, 04:31:13 pm
-
I need to read and write raw data. By raw data I mean reading/writing bytes as you would see them using a packet sniffer like http://wpepro.net/
To do this I understand that SFML reads/writes a character array/char*
However, when I try to receive a packet I do not think it is being read correctly because when I print it to the console I see gibberish.
This is what a piece of my code looks like:
if ( _authServer.Connect( _authIP, _authPort, 10.0f ) == sf::Socket::Done )
{
std::cout << "[SYSTEM] - CONNECTED TO AUTHENTICATION SERVER.\n";
char loginPacket[8] = { 0 };
std::size_t received;
_authServer.Receive( loginPacket, sizeof( loginPacket ), received );
_crypt.Decrypt( (unsigned char*)loginPacket, 8 );
for ( int i = 0; i < sizeof( loginPacket ); i++ )
{
std::cout << std::hex << loginPacket[i] << "\t";
}
std::cout << std::endl;
}
-
What do you see exactly, and what do you expect to see?
Have you tried without calling your Decrypt function?
-
I see special characters instead of numbers.
edit:
Just realized I forgot to perform a cast when printing to the console. Not in a position right now to check it out but would you agree this solves the problem?
-
Indeed, if you want to see numbers instead of characters, you have to cast to int ;)
-
Why char? Why not unsigned char?
-
neither char nor unisgned char, you'll have to cast to an int in order to see the byte value. a char (unsigned or not) will be showed on the console as a character (using the ASCII table).
So "8" will be a backspace for example.
I had the same problem while doing my Telnet class :)
-
neither char nor unisgned char, you'll have to cast to an int in order to see the byte value. a char (unsigned or not) will be showed on the console as a character (using the ASCII table).
So "8" will be a backspace for example.
I had the same problem while doing my Telnet class :)
I am talking about why SFML takes char instead of unsigned char. o.0
-
I am talking about why SFML takes char instead of unsigned char. o.0
What would it change? The type doesn't really matter anyway, it could be char*, unsigned char*, or void* as well.
-
I am talking about why SFML takes char instead of unsigned char. o.0
What would it change? The type doesn't really matter anyway, it could be char*, unsigned char*, or void* as well.
Generally raw data comes with encryption and it is a good idea to be using unsigned.
But you are right, the type doesn't really matter you can just cast.