根据示例创建一个简单的TCP服务器,但仍然没有得到如何创建一个读取一定数量字节的套接字,如果没有足够的将等待.我需要这不是异步操作.
#include <iostream>
#include <boost/asio.hpp>
#ifdef _WIN32
#include "Windows.h"
#endif
using namespace boost::asio::ip;
using namespace std;
int main(){
int m_nPort = 12345;
boost::asio::io_service io_service;
tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), m_nPort));
cout << "Waiting for connection..." << endl;
tcp::socket socket(io_service);
acceptor.accept(socket);
cout << "connection accepted" << endl;
try
{
socket.send(boost::asio::buffer("Start sending me data\r\n"));
}
catch(exception &e)
{
cerr << e.what() << endl; //"The parameter is incorrect" exception
}
}
Run Code Online (Sandbox Code Playgroud)
如何接收10000个字节并执行它直到所有10000到达或1000毫秒超时并抛出异常?