• 大小: 0.08M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-01-29
  • 语言: C/C++
  • 标签: tcp  c++  c  源码  

资源简介

CSockClient* GetNewSockClient ()
{
CSockClient *pSockClient = new CSockClient;
if ( !pSockClient )
{
printf ( "New SockClient object failed\n" );
return NULL;
}
g_CSFor_PtrAry_SockClient.Lock();
g_PtrAry_SockClient.Add ( pSockClient );
pSockClient->m_dwID = g_nSockClientID;
g_CSFor_PtrAry_SockClient.Unlock();
printf ( "Current SocketClient array count is %d\n", g_PtrAry_SockClient.GetSize() );

return pSockClient;
}

//
// 将新客户端登录信息发送给所有已登录的客户端,但不发送给自己
//
BOOL SendNewUserLoginNotifyToAll ( LPCTSTR lpszClientIP, UINT nClientPort, DWORD dwID )
{
ASSERT ( lpszClientIP && nClientPort > 0 );
g_CSFor_PtrAry_SockClient.Lock();
for ( int i=0; i<g_PtrAry_SockClient.GetSize(); i )
{
CSockClient *pSockClient = (CSockClient*)g_PtrAry_SockClient.GetAt(i);
if ( pSockClient && pSockClient->m_bMainConn && pSockClient->m_dwID > 0 && pSockClient->m_dwID != dwID )
{
if ( !pSockClient->SendNewUserLoginNotify ( lpszClientIP, nClientPort, dwID ) )
{
g_CSFor_PtrAry_SockClient.Unlock();
return FALSE;
}
}
}

g_CSFor_PtrAry_SockClient.Unlock ();
return TRUE;
}

CSockClient* FindSocketClient ( DWORD dwID )
{
g_CSFor_PtrAry_SockClient.Lock ();
for ( int i=0; i<g_PtrAry_SockClient.GetSize(); i )
{
CSockClient *pSockClient = (CSockClient*)g_PtrAry_SockClient.GetAt(i);
if ( pSockClient && pSockClient->m_dwID == dwID )
{
g_CSFor_PtrAry_SockClient.Unlock ();
return pSockClient;
}
}
printf ( "Can't find ID:%u\n", dwID );
g_CSFor_PtrAry_SockClient.Unlock ();
return NULL;
}

资源截图

代码片段和文件信息

#include “stdafx.h“
#include “global.h“

CString hwFormatMessage ( DWORD dwErrorCode )
{
CString csError;
LPVOID pv;
    FormatMessage (
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
NULL
dwErrorCode
MAKELANGID(LANG_NEUTRALSUBLANG_DEFAULT)
(LPTSTR)&pv
0
NULL);
if(pv)
{
csError = (char*)pv;
LocalFree ( pv );
}

return csError;
}
//
// 等待线程退出
//
BOOL WaitForThreadEnd ( HANDLE *phThread DWORD dwWaitTime /*=5000*/ )
{
BOOL bRet = TRUE;
ASSERT ( phThread );
if ( !(*phThread) ) return TRUE;
if ( ::WaitForSingleobject ( *phThread dwWaitTime ) == WAIT_TIMEOUT )
{
bRet = FALSE;
::TerminateThread ( *phThread 0 );
}
::CloseHandle ( *phThread );
(*phThread) = NULL;
return bRet;
}

BOOL WaitForThreadEn

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1186  2007-07-22 11:32  global.cpp

     文件      11124  2007-07-23 23:03  global.h

     目录          0  2007-07-24 02:04  Bin

     文件      24576  2007-07-24 01:24  Bin\TcpHoleClt-A.exe

     文件      24576  2007-07-24 01:24  Bin\TcpHoleClt-B.exe

     文件      24576  2007-07-24 01:24  Bin\TcpHoleSrv.exe

     文件        607  2007-07-24 02:04  Bin\程序执行步骤和方法.txt

     目录          0  2007-07-24 02:08  TcpHoleClt

     文件        451  2007-07-22 14:22  TcpHoleClt\Resource.h

     文件        297  2007-07-22 14:22  TcpHoleClt\StdAfx.cpp

     文件       1154  2007-07-22 14:22  TcpHoleClt\StdAfx.h

     文件        406  2007-07-22 14:22  TcpHoleClt\TcpHoleClt.clw

     文件      20852  2007-07-24 01:06  TcpHoleClt\TcpHoleClt.cpp

     文件       4460  2007-07-23 02:21  TcpHoleClt\TcpHoleClt.dsp

     文件        379  2007-07-22 14:22  TcpHoleClt\TcpHoleClt.h

     文件       1916  2007-07-24 01:24  TcpHoleClt\TcpHoleClt.plg

     文件       1457  2007-07-22 14:22  TcpHoleClt\TcpHoleClt.rc

     文件        545  2007-07-22 14:22  TcpHoleClt\TcpHoleClt_A.dsw

     文件      66560  2007-07-24 02:08  TcpHoleClt\TcpHoleClt_A.ncb

     文件      48640  2007-07-24 02:08  TcpHoleClt\TcpHoleClt_A.opt

     文件        545  2007-07-22 14:22  TcpHoleClt\TcpHoleClt_B.dsw

     文件      82944  2007-07-24 01:24  TcpHoleClt\TcpHoleClt_B.ncb

     文件      48640  2007-07-24 01:24  TcpHoleClt\TcpHoleClt_B.opt

     目录          0  2007-07-24 02:08  TcpHoleSrv

     文件        451  2007-07-22 10:26  TcpHoleSrv\Resource.h

     文件      10590  2007-07-23 19:11  TcpHoleSrv\SockClient.cpp

     文件       1811  2007-07-23 12:11  TcpHoleSrv\SockClient.h

     文件        297  2007-07-22 10:26  TcpHoleSrv\StdAfx.cpp

     文件       1154  2007-07-22 10:30  TcpHoleSrv\StdAfx.h

     文件      16924  2007-07-23 13:42  TcpHoleSrv\TcpHoleSrv.aps

............此处省略13个文件信息

评论

共有 条评论