Created
April 19, 2012 19:18
-
-
Save bechu/2423333 to your computer and use it in GitHub Desktop.
simple boost tcp client example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
g++ main.cpp -lboost_system -lboost_thread -lpthread -o main | |
*/ | |
#include <boost/asio.hpp> | |
#include <boost/array.hpp> | |
#include <iostream> | |
void send_something(std::string host, int port, std::string message) | |
{ | |
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.close(); | |
} | |
int main() | |
{ | |
send_something("127.0.0.1", 1990, "hello flowers team"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment