Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Sockets
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++)
{
	sendBuffer.push_back(cmd[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:
ffffffff72636f6e203133333720737461747573
This is what I supposed to send.
HEX Stream:
88e5540070e6540084e654008ce65400cccccccc
That's what my application sends.
Posted 23-Nov-12 21:23pm
ProDavy642
Comments
Richard MacCutchan at 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
good
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 );
  Permalink  
v3
Comments
ProDavy at 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 at 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)

  Print Answers RSS
0 OriginalGriff 299
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 230
3 Aajmot Sk 191
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 24 Nov 2012
Copyright © CodeProject, 1999-2014
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