I need help, I'm trying to send this data in hexadeciamal, but always the packet_byte.size() and date() says: the express needs to have type of calsse, but has the type "char". I dont now what i need do, if anyone can help me.and if you can indicate what to study to understand this error Thank you.
#include <iostream>
#define ASIO_STANDALONE
#ifdef _WIN32
#define _WIN32_WINNT 0x0A00
#endif
#include <asio.hpp>
#include <asio/ts/buffer.hpp>
#include <asio/ts/internet.hpp>
int main() {
asio::error_code ec; //pega erros especificos
//Cria o "context"
asio::io_context context;
//Pega o endereço no qual estamos conectando1
asio::ip::tcp::endpoint endpoint(asio::ip::make_address("ip", ec), 15559);
//Cria o socket, o context ira entregar a implementaçao
asio::ip::tcp::socket socket(context);
//Diz ao socket para tentar se conectar
socket.connect(endpoint, ec);
if (!ec) {
std::cout << "Conectado!" << std::endl;
}
else {
std::cout << "Falha de conecxao com o endereço: \n" << ec.message()/*pega mensagem associada ao erro */ << std::endl;
}
//Verifia se esta conectado
if (socket.is_open()) {
const unsigned char packet_bytes [] = {
"0x1e, 0x00, 0xe0, 0x55, 0xc0, 0x52, 0x09, 0x00,"
"0x41, 0x00, 0x73, 0x00, 0x70, 0x00, 0x70, 0x00,"
"0x69, 0x00, 0x65, 0x00, 0x72, 0x00, 0x72, 0x00,"
"0x00, 0x00, 0x08, 0x9b, 0x95, 0x01"
};
//Se conexçao for True, escreve:
//asio::buffer e um container, contendo bytes da string e sizer.
socket.write_some(asio::buffer(packet_bytes.data(), packet_bytes.size()), ec);
//Estava dando erro pelo tempo de resposta, programa indo mais rapido que a resposta.
socket.wait(socket.wait_read);
size_t bytes = socket.available();
std::cout << "Bytes Available: " << bytes << std::endl;
if (bytes > 0) {
//adiciona dados recebidos em um vector
std::vector<char> vBuffer(bytes);
socket.read_some(asio::buffer(vBuffer.data(), vBuffer.size()), ec);
//
for (auto c : vBuffer) {
std::cout << c;
}
}
}
system("pause");
return 0;
}```