测试协同CS模式下的客户端操作通知时间 采用协议TCP

方法1:抓取发送的数据包和接收的数据,获取时间

方法2:由发送者将自己的时间作为一项数据发送给接收者

方法3:采用日志,记录发送时间和接收时间

#pragma once
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include<string>
#include<fstream>
#include<time.h>
using namespace std;
class LogHelper
{
public:
	LogHelper(void);
	void Init(BLL* pBLL);
	~LogHelper(void);
	//string actorstr;发送、接收;string opstr操作类型:删除、拖动、分割删除、效果、编辑
	void WriteLog(char* actor_str,char* op_str);
private:
	CRITICAL_SECTION csLogWrite;  //多线程
	BLL* pBLL;
};

#include "LogHelper.h"

LogHelper::LogHelper(void)
{
}
void LogHelper::Init(BLL* pBLL)
{
	InitializeCriticalSection(&csLogWrite); 
	this->pBLL = pBLL;
}
LogHelper::~LogHelper(void)
{
	DeleteCriticalSection(&csLogWrite);
}
void LogHelper::WriteLog(char* actor_str,char* op_str)
{
	EnterCriticalSection(&csLogWrite);
	try
	{
		//获取当前日期
		time_t t = time(0);
		char tmp[64];
		strftime(tmp,sizeof(tmp),"%Y%m%d",localtime(&t));
		ofstream fout;
		char fileName[100];
		if(strcmp(pBLL->dirName,"")!=0)
			sprintf(fileName,"%s\\%s_%s.Log",pBLL->dirName,pBLL->myName,tmp); 
		else
			sprintf(fileName,"%s_%s.Log",pBLL->myName,tmp); 
		fout.open(fileName,ios::app);
		if(fout.is_open())
		{
			SYSTEMTIME sys_time;
			GetLocalTime(&sys_time);
			char msg[100];
			sprintf(msg,"%4d/%02d/%02d %02d:%02d:%02d.%03d %s%s",sys_time.wYear,sys_time.wMonth,sys_time.wDay,sys_time.wHour,sys_time.wMinute,sys_time.wSecond,sys_time.wMilliseconds,actor_str,op_str); 
			fout<<msg<<endl;
			fout.close();
		}
	}
	catch (exception &e)
	{
		
	}
	finally
	{
		LeaveCriticalSection(&csLogWrite);
	}
	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值