www.gusucode.com > VC++写的中国象棋游戏源程序源码程序 > VC++写的中国象棋游戏源程序源码程序\code\client.cpp

    #include <stdafx.h>
#include "blocksocket.h"
#include "globle.h"
// Download by http://www.NewXing.com
// clientsockthread.cpp (uses Winsock calls only)
UINT ClientThreadProc(LPVOID pParam)
{
	// sends a blind request, followed by a request for a specific URL
	CHttpBlockingSocket sClient;
	char* buf = new char[100];
	
	
	CSockAddr saServer, saPeer, saTest, saClient;
	try {
		sClient.Create();

		//saServer = CBlockingSocket::GetHostByName(g_strIPServer, g_nPortServer);
		saServer = CSockAddr(g_dwIPServer, g_nPortServer);
	
		sClient.Connect(saServer);
		
		sClient.GetSockAddr(saTest);
	
		TRACE("SOCK CLIENT: GetSockAddr = %s, %d\n", saTest.DottedDecimal(), saTest.Port());
	
		CString s;
		s.Format("%d\r\n", g_side);
		sClient.Write(s, s.GetLength(), 300);
		
		// read all the server's response headers
		for(;;)
		{
			if(g_side == RED_SIDE)
			{
				::WaitForSingleObject(g_eventStart, INFINITE);
				sClient.Write(g_stringInfo, g_stringInfo.GetLength(), 300);
				sClient.ReadHttpHeaderLine(buf, MAXLINELENGTH, 300);
				::SendMessage((HWND) pParam, WM_START, (WPARAM) 0, (LPARAM) buf);
			}
			else
			{
				sClient.ReadHttpHeaderLine(buf, MAXLINELENGTH, 300);
				::SendMessage((HWND) pParam, WM_START, (WPARAM) 0, (LPARAM) buf);
				::WaitForSingleObject(g_eventStart, INFINITE);
				sClient.Write(g_stringInfo, g_stringInfo.GetLength(), 300);
			}
		}
	}
	catch(CBlockingSocketException* e) {
		LogBlockingSocketException(pParam, "CLIENT:", e);
		e->Delete();
	}
	sClient.Close();
	delete [] buf;
	return 0;
}