Click here to Skip to main content
13,145,068 members (54,283 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello everyone.
I would like if you could take a look at my code and tell me what's wrong with it.
// Converting ASCII into byte code array
string cmd = "rcon 1337 status";
vector<BYTE> sendBuffer (4, 255);
for (int i = 0; i < cmd.length(); i++)

// 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.
HEX Stream:

This is what I supposed to send.
HEX Stream:

That's what my application sends.
Posted 23-Nov-12 20:23pm
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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...

send( mySocket, cmd, (int)strlen(cmd), 0 );
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...

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 24 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100