c++ - Sending data from a boost asio client -


i trying write program can send data on network java server listening on 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; } 

when use program keep getting error message below:

c4996: 'std::_copy_impl': function call parameters may unsafe -     call relies on caller check passed values correct. disable warning, use -d_scl_secure_no_warnings. see documentation on how use visual c++ 'checked iterators' c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility 2132    1   consoleapplication1 

i have tried warning , not found result related error. there better way write code? new c++ , not have idea how boost working. using visual studio 2013 , boost 1.60.0.

not answer question rather workaround.

i think error comes std::copy call, bypass using data method std::string directly buffer array instead of copying in boost::array.

like :

socket.write_some(boost::asio::buffer(message.data(), message.size()), error);


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -