ServerSocket.cpp
资源名称:QQ示例源码.rar [点击查看]
上传用户:power_led
上传日期:2013-04-11
资源大小:373k
文件大小:3k
源码类别:
ICQ/即时通讯
开发平台:
Visual C++
- // ServerSocket.cpp : implementation file
- //
- #include "stdafx.h"
- #include "CChatServer.h"
- #include "ServerSocket.h"
- #include "ClientSocket.h"
- #include "MainFrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CServerSocket
- CServerSocket::CServerSocket()
- {
- }
- CServerSocket::~CServerSocket()
- {
- }
- // Do not edit the following lines, which are needed by ClassWizard.
- #if 0
- BEGIN_MESSAGE_MAP(CServerSocket, CSocket)
- //{{AFX_MSG_MAP(CServerSocket)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- #endif // 0
- /////////////////////////////////////////////////////////////////////////////
- // CServerSocket member functions
- extern CCChatServerApp theApp;
- void CServerSocket::OnAccept(int nErrorCode)
- {
- // TODO Add your specialized code here and/or call the base class
- g_cs.Lock();
- CClientSocket * m_pNewClient = new CClientSocket();
- ASSERT(m_pNewClient != NULL);
- Accept(*m_pNewClient);
- CMainFrame * pFrame = static_cast <CMainFrame *>(AfxGetMainWnd());
- /* //发送所有的房间列表
- Message msObj;
- ::ZeroMemory(&msObj,sizeof(msObj));
- msObj.iType = USERLOG;
- msObj.iSubType = ROOMLIST;
- if(theApp.m_ChatRoomList.GetCount())
- {
- POSITION pos = theApp.m_ChatRoomList.GetHeadPosition();
- if(pos)
- {
- for(int i = 0 ; i < theApp.m_ChatRoomList.GetCount();i ++)
- {
- CString * m_pstrRoom = static_cast < CString *>(theApp.m_ChatRoomList.GetNext(pos));
- ASSERT(m_pstrRoom != NULL);
- int iLen = m_pstrRoom->GetLength();
- iLen > 20 ? iLen : 20;
- lstrcpy(msObj.strRoom,m_pstrRoom->GetBuffer(iLen));
- m_pNewClient->Send(&msObj,sizeof(msObj));
- CString strOut;
- strOut.Format("%d %d %s %sn",msObj.iType,msObj.iSubType,msObj.strRoom,msObj.strName);
- TRACE0(strOut);
- Sleep(200);
- }
- }
- }
- //发送所有的用户资料
- msObj.iType = USERLOG;
- msObj.iSubType = USERLIST;
- CPtrList * m_pClientList = theApp.m_pClientSocketList;
- POSITION pos = m_pClientList ->GetHeadPosition();
- int iCount = m_pClientList ->GetCount();
- if(pos && iCount > 0)
- { CClientSocket * m_pClientSocket;
- for(int i = 0; i < iCount; i++)
- {
- m_pClientSocket = static_cast < CClientSocket *>(m_pClientList->GetNext(pos));
- CString strTemp = m_pClientSocket ->GetRoomName();
- int iLen = strTemp.GetLength();
- iLen > 20 ? 20 : iLen;
- lstrcpy(msObj.strRoom,strTemp.GetBuffer(iLen));
- strTemp.ReleaseBuffer();
- strTemp = m_pClientSocket ->GetUserName();
- iLen = strTemp.GetLength();
- iLen > 20 ? 20 : iLen;
- lstrcpy(msObj.strName,strTemp.GetBuffer(iLen));
- strTemp.ReleaseBuffer();
- m_pNewClient->Send(&msObj,sizeof(msObj));
- Sleep(100);
- }
- }
- theApp.m_pClientSocketList->AddTail(m_pNewClient);
- g_cs.Unlock();*/
- return;
- }