#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
using boost::asio::ip::tcp;
#include "boost/date_time/posix_time/posix_time.hpp" //include all types plus i/o
#include "boost/date_time/posix_time/time_parsers.hpp"
#include <string>
#include <iostream>
#include <windows.h>
//#include <iostream>
//#include <boost/asio.hpp>
//#include <boost/bind.hpp>
#include <boost/thread/thread.hpp>
//#include <boost/date_time/posix_time/posix_time.hpp>
#include <process.h>
class client
{
protected:
static unsigned int __stdcall sendCheckMsg(PVOID pThis)
{
client* pClient = (client*)pThis;
while(true)
{
Sleep(5000);
char checkBuf[32];
memset(checkBuf, 0, sizeof(checkBuf));
strcpy(checkBuf, "message\r\n");
boost::asio::async_write(pClient->socket,boost::asio::buffer(checkBuf),
boost::bind(&client::handle_write,pClient,boost::asio::placeholders::error));
}
return 0;
}
void set_timer()
{
::_beginthreadex(NULL, 0, sendCheckMsg, (PVOID)this, 0, NULL);
}
private:
tcp::socket socket;
char getBuffer[1024];
int iWaitMicroSenconds;
bool timerSet;
};
在类中使用_beginthreadex函数创建线程并访问该类中的数据成员
最新推荐文章于 2024-06-07 14:45:31 发布