日期:2014-05-16 浏览次数:21209 次
main(...)
{
boost::asio::io_service io_service;
tcp::socket socket(io_service);
socket.async_connect(boost::asio::ip::tcp::endpoint(boost::asio::ip::address(), 5050),
connect_handler);
io_service.poll(); //connect_handler被调用了,连接成功
boost::system::error_code error;
size_t len = strlen(buff) + 1;
boost::asio::mutable_buffers_1 send_buff = boost::asio::buffer(buff, len);
boost::asio::async_write(socket, send_buff, boost::asio::transfer_at_least(len), send_handler);
cout << "io_service.run() " << io_service.poll() << endl;
//send_handler没有被调用,io_service.poll()返回0
// TestBoost.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <boost/asio.hpp>
#include <iostream>
using namespace std;
using boost::asio::ip::tcp;
void connect_handler(const boost::system::error_code& error /*Result of operation*/);
void send_handler(const boost::system::error_code& error /*Result of operation*/, size_t bytes_transferred);
int _tmain(int argc, _TCHAR* argv[])
{
/*
boost::asio::io_service io;
boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));