将ASCII转换为字节码数组,然后通过UDP套接字发送. [英] Converting ASCII into byte code array and sending it over UDP socket.

查看:601
本文介绍了将ASCII转换为字节码数组,然后通过UDP套接字发送.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.
我希望您能看一下我的代码并告诉我它有什么问题.

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 );


一切都按我的预期进行.
但是当我用Wireshark嗅探数据包时,有些事情是不对的.


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.

推荐答案

我不知道为什么将char缓冲区更改为byte然后发送,我认为直接遵循以下代码与您的const char *一起使用.如果出于任何原因要转换为字节,请在另一端进行转换.通过更改为以下代码,它应该可以工作...

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 );


这篇关于将ASCII转换为字节码数组,然后通过UDP套接字发送.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆