Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone.
I would like if you could take a look at my code and tell me what's wrong with it.
C++
// Converting ASCII into byte code array
string cmd = "rcon 1337 status";
vector<BYTE> sendBuffer (4, 255);

for (int i = 0; i < cmd.length(); i++)
{
	sendBuffer.push_back(cmd[i]);
}

C++
// Sending vector over UDP socket and receiving the response.
char recBuffer[6500];

send( mySocket, (char *)&sendBuffer, sendBuffer.size(), 0 );
recv( mySocket, recBuffer, sizeof(recBuffer), 0 );

Everything works as I intended.
But when I sniff the packets with Wireshark something is not right.
C++
HEX Stream:
ffffffff72636f6e203133333720737461747573

This is what I supposed to send.
C++
HEX Stream:
88e5540070e6540084e654008ce65400cccccccc

That's what my application sends.
Posted
Comments
Richard MacCutchan 24-Nov-12 4:58am    
This does not make a lot of sense. What are you trying to send in total? As Dharmateja says below you can just send the string as is, there is no point in moving it into a vector.

1 solution

I don't know why you are changing char buffer to byte and then sending it, I think following code directly works with your const char*. If there is any reason you want to convert into byte, convert at the other end. By changing to below code it should work...

C++
send( mySocket, cmd, (int)strlen(cmd), 0 );
 
Share this answer
 
v3
Comments
ProDavy 24-Nov-12 3:21am    
I need to pop 4 bytes in front of cmd and then convert it from ASCII to DEC before I can send it. The problem is no matter what vector type I use (int, char, byte) I have the wrong packet at the end. Check first code snipped to see the ASCII to DEC conversion.
Dharmateja Challa 24-Nov-12 9:05am    
This will answer your query...
http://social.msdn.microsoft.com/Forums/en/vclanguage/thread/42268023-b3eb-4f6a-ac19-d83cdcc65ad8

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900