⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.cpp

📁 chess game wirte by Visual C++
💻 CPP
字号:
#include "globle.h"
#include <stdafx.h>
#include "blocksocket.h"
#include "globle.h"

void LogRequest(LPVOID pParam, char* pch, CSockAddr sa)
{
	//wsprintf(text1, "SERVER CONNECTION # %d: IP addr = %s, port = %d -- %s\r\n",
	//	g_nConnection, sa.DottedDecimal(), sa.Port(),  (const char*) strGmt);
	
	
	::SendMessage((HWND) pParam, WM_CONNECTED, (WPARAM) 0, (LPARAM) pch);
}

UINT ServerThreadProc(LPVOID pParam)
{
	CSockAddr saClient;
	CHttpBlockingSocket sConnect;
	char* buf = new char[100];
	
	//CString strGmtNow = CTime::GetCurrentTime().FormatGmt("%a, %d %b %Y %H:%M:%S GMT");

	int nBytesSent = 0;
	
	try
	{
		if(!g_sListen.Accept(sConnect, saClient))
		{
			// view or application closed the listing socket
			g_bListening = FALSE;
			delete [] buf;
			return 0;
		}
		// read request from client
		sConnect.ReadHttpHeaderLine(buf, MAXLINELENGTH, 300);
		LogRequest(pParam, buf, saClient);
		for(;;)
		{
			if(g_side == RED_SIDE)
			{
				::WaitForSingleObject(g_eventStart, INFINITE);
				sConnect.Write(g_stringInfo, g_stringInfo.GetLength(), 300);
				sConnect.ReadHttpHeaderLine(buf, MAXLINELENGTH, 300);
				::SendMessage((HWND) pParam, WM_START, (WPARAM) 0, (LPARAM) buf);
			}
			else
			{
				sConnect.ReadHttpHeaderLine(buf, MAXLINELENGTH, 300);
				::SendMessage((HWND) pParam, WM_START, (WPARAM) 0, (LPARAM) buf);
				::WaitForSingleObject(g_eventStart, INFINITE);
				sConnect.Write(g_stringInfo, g_stringInfo.GetLength(), 300);
			}
		}
	}
	catch(CBlockingSocketException* pe) {
		LogBlockingSocketException(pParam, "SERVER:", pe);
		pe->Delete();
	}
	TRACE("SERVER: file characters sent = %d\n", nBytesSent);
	delete [] buf;
	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -