I am trying to write a program which can send data over a network to my Java server listening on a port.
#include "stdafx.h"
#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <iostream>
void do_somenetwork(std::string host, int port, std::string message)
{
std::array<char, 1024> _arr;
boost::asio::io_service ios;
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string(host), port);
boost::asio::ip::tcp::socket socket(ios);
socket.connect(endpoint);
boost::array<char, 128> buf;
std::copy(message.begin(), message.end(), buf.begin());
boost::system::error_code error;
socket.write_some(boost::asio::buffer(buf, message.size()), error);
socket.read_some(boost::asio::buffer(_arr));
std::cout.write(&_arr[0], 1024);
socket.close();
}
int main(){
do_somenetwork(std::string("127.0.0.1"), 50000, ";llsdfsdf");
char ch;
std::cin >> ch;
}
C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility 2132 1 ConsoleApplication1
Not really the answer to your question but rather a workaround.
I think the error comes from the std::copy
call, you could bypass it by using the data method from std::string
directly as the buffer array instead of copying it in your boost::array
.
Like this :
socket.write_some(boost::asio::buffer(message.data(), message.size()), error);