91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 813KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-23
  • 語言: C/C++
  • 標簽: 多線程??C/S??

資源簡介

//**************************************************** // File: HB_Server.cpp // Language: Visual C++ // IDE: VS2010 // Project: Win32 Console+預編譯頭 // Author: Dearggae // Date: 2012.10.31 // Function: 支持不同類型信息的接收回射服務器 //**************************************************** //**************************************************** // File: HB_Client.cpp // Language: Visual C++ // IDE: VS2010 // Project: Win32 Console+預編譯頭 // Author: Dearggae // Date: 2012.10.31 // Function: 支持不同類型信息的發送回射客戶端 //****************************************************

資源截圖

代碼片段和文件信息

//****************************************************
//?File: HB_Client.cpp?
//?Language: Visual?C++
//?IDE: VS2010
//?Project: Win32?Console+預編譯頭
//?Author: Dearggae
//?Date: 2012.10.31
//?Function: 支持不同類型信息的發送回射客戶端
//****************************************************


#include?“stdafx.h“
#include?“typedef.h“
#include?
#include?“windows.h“
#include?

#include?
#pragma?comment(lib“WS2_32.lib“)



DWORD?WINAPI?SendThread(LPVOID); //發送線程函數
DWORD?WINAPI?RecvThread(LPVOID); //接收線程函數
DWORD?WINAPI?HBThread(LPVOID); //心跳線程函數
void?CheckError(intchar*); //查錯處理
STRING?GetSystemTime(); //獲取系統時間
void?Close(); //釋放服務器
SOCKET?sHost;
int?Ret;

int?_tmain(int?argc?_TCHAR*?argv[])
{
WSADATA?wsd;
SOCKADDR_IN?Server;
DWORD?SendThreadId;
DWORD?RecvThreadId;
DWORD?HBThreadId;

int?iaddrSize?=?sizeof(SOCKADDR_IN);

//初始化WinSocket環境
if(WSAStartup(MAKEWORD(22)&wsd)?!=?0)
{
printf(“WSAStartup?failed?!\n“);
system(“pause“);
exit(0);
}
//創建監聽Socket
sHost?=?socket(AF_INETSOCK_STREAMIPPROTO_TCP);
if(INVALID_SOCKET?==?sHost)
{
printf(“socket?failed?!\n“);
system(“pause“);
exit(0);
}

//綁定
Server.sin_family?=?AF_INET;
Server.sin_port?=?htons(PORT);
Server.sin_addr.S_un.S_addr?=?inet_addr(SERVER_IP);

//綁定Sockets?Server到本地地址
Ret?=?connect(sHost(LPSOCKADDR)&Serversizeof(Server));
CheckError(Ret“HB_Client():?Connect?Failed“);
printf(“Connect?Success?!?\n“);

//================================================
CreateThread(NULL?0?SendThread?NULL?0?&SendThreadId);

CreateThread(NULL?0?RecvThread?NULL?0?&RecvThreadId);

CreateThread(NULL?0?HBThread?NULL?0?&HBThreadId);

Sleep(1000000);

return?0;
}


DWORD?WINAPI?SendThread(LPVOID?lpParam)
{
char?msg[MSG_SIZE];
char?buf[MSG_SIZE+HEAD_SIZE];

while(true)
{
Sleep(SEND_TIME);
ZeroMemory(msgMSG_SIZE);
ZeroMemory(bufMSG_SIZE);
printf(“Please?input?a?string?to?send?(send?exit?~?):?“);
std::string?str;
getline(std::cinstr);
strcpy_s(msgstr.c_str());
sprintf_s(buf“%04d%s“MSG_COMmsg);
Ret?=?send(sHostbufstrlen(buf)0);
CheckError(Ret“SendThread:?Send?Failed“);
while?(Ret<=0) //實現超時重發功能
{
Sleep(SEND_TIMEOUT);
Ret?=?send(sHostbufstrlen(buf)0);
}
}
return?0;
}


DWORD?WINAPI?RecvThread(LPVOID?lpParam)
{
char?buf[MSG_SIZE+HEAD_SIZE];
char?msg[MSG_SIZE];
char?head[HEAD_SIZE+1];
int?MsgType;
int?len;

while(TRUE)
{
ZeroMemory(headHEAD_SIZE+1);
ZeroMemory(msgMSG_SIZE);
ZeroMemory(bufMSG_SIZE+HEAD_SIZE);
Ret?=?recv(sHostbufMSG_SIZE+HEAD_SIZE0);
CheckError(Ret“RecvThread:?Recv?Failed“);
len?=?strlen(buf);
strncpy_s(headbufHEAD_SIZE);
sscanf_s(head“%d\n“&MsgType);
strncpy_s(msgbuf+HEAD_SIZElen-HEAD_SIZE);

switch?(MsgType)
{
case?MSG_COM?:
printf(“%s?Recv?From?Server?:?%s\n“GetSystemTime().strmsg)

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????1602??2012-10-31?11:08??HB_Client\Debug\cl.command.1.tlog

?????文件??????23914??2012-10-31?11:08??HB_Client\Debug\CL.read.1.tlog

?????文件???????1032??2012-10-31?11:08??HB_Client\Debug\CL.write.1.tlog

?????文件????????406??2012-10-30?21:23??HB_Client\Debug\HB_Client.exe.embed.manifest

?????文件????????472??2012-10-30?21:23??HB_Client\Debug\HB_Client.exe.embed.manifest.res

?????文件????????381??2012-10-31?11:08??HB_Client\Debug\HB_Client.exe.intermediate.manifest

?????文件?????????73??2012-10-31?11:08??HB_Client\Debug\HB_Client.lastbuildstate

?????文件???????2358??2012-10-31?11:08??HB_Client\Debug\HB_Client.log

?????文件?????134450??2012-10-31?11:08??HB_Client\Debug\HB_Client.obj

?????文件????1179648??2012-10-30?21:14??HB_Client\Debug\HB_Client.pch

?????文件????????208??2012-10-30?21:14??HB_Client\Debug\HB_Client_manifest.rc

?????文件??????????2??2012-10-31?11:08??HB_Client\Debug\link-cvtres.read.1.tlog

?????文件??????????2??2012-10-31?11:08??HB_Client\Debug\link-cvtres.write.1.tlog

?????文件??????????2??2012-10-31?11:08??HB_Client\Debug\link.14372-cvtres.read.1.tlog

?????文件??????????2??2012-10-31?11:08??HB_Client\Debug\link.14372-cvtres.write.1.tlog

?????文件??????????2??2012-10-31?11:08??HB_Client\Debug\link.14372.read.1.tlog

?????文件??????????2??2012-10-31?11:08??HB_Client\Debug\link.14372.write.1.tlog

?????文件??????????2??2012-10-31?11:08??HB_Client\Debug\link.23952-cvtres.read.1.tlog

?????文件??????????2??2012-10-31?11:08??HB_Client\Debug\link.23952-cvtres.write.1.tlog

?????文件??????????2??2012-10-31?11:08??HB_Client\Debug\link.23952.read.1.tlog

?????文件??????????2??2012-10-31?11:08??HB_Client\Debug\link.23952.write.1.tlog

?????文件??????????2??2012-10-31?11:08??HB_Client\Debug\link.9420-cvtres.read.1.tlog

?????文件??????????2??2012-10-31?11:08??HB_Client\Debug\link.9420-cvtres.write.1.tlog

?????文件??????????2??2012-10-31?11:08??HB_Client\Debug\link.9420.read.1.tlog

?????文件??????????2??2012-10-31?11:08??HB_Client\Debug\link.9420.write.1.tlog

?????文件???????1838??2012-10-31?11:08??HB_Client\Debug\link.command.1.tlog

?????文件???????3744??2012-10-31?11:08??HB_Client\Debug\link.read.1.tlog

?????文件???????1094??2012-10-31?11:08??HB_Client\Debug\link.write.1.tlog

?????文件????????426??2012-10-31?11:08??HB_Client\Debug\mt.command.1.tlog

?????文件????????594??2012-10-31?11:08??HB_Client\Debug\mt.read.1.tlog

............此處省略73個文件信息

評論

共有 條評論