资源简介
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;
}
{
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个文件信息
- 上一篇:get获取网页源代码
- 下一篇:监听webbrowser所有请求
相关资源
- VC基本图像处理源码集
- c++ 直线裁剪、画矩形等(graphics)
- SpaceClaim2016_SP0_UsersGuide
- CUDA 编程4.2(CUDA_C_Programming_Guide_4.2)
- 圆环纹理映射(c++项目)
- opencv 动物识别
- 《DirectX游戏开发终极指南》随书源码
- 人脸特征点检测,轻量级的MTCNN实现
- visual c++数字图像模式识别技术详解
- Learning OpenCV3 英文版
- VC+MFC实现真实感图形(正方体+菊花)
- cuda c编程(CUDA_C_Programming_Guide)
- OpenCV实现移动跟踪非常简单
- Qt5C++GUIProgrammingCookbook(PDF+源码)
- c++ 电子海图简单程序
- 《从0到1教你写uCOS-III》pdf 图文教程(
- C++/Qt 期货数据获取
- c++ 实时获取光标处颜色(类似抓色器
- c++ 执行脚本的程序(一键安装全部卸
- 定时器 c++源码
- office 文档自动打印
- 7z sdk的C++封装
- vc6 读取 shp文件
- 单片机与PC机串口通信的类程序
- Amcap源码
- c++ 压缩文件/解压缩文件 (亲测通过
- c++ 串口通信Demo源码(方便学习调试)
- 通过图像实现Z轴定位(opencv)
- 邓俊辉数据结构(C++版)第三版
- C程序设计
评论
共有 条评论