📄 serversock.cpp
字号:
// ServerSock.cpp : implementation file
//
#include "stdafx.h"
#include "CVoiceChat.h"
#include "ServerSock.h"
#include "CVoiceChatDlg.h"
#include "windows.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CServerSock
CServerSock::CServerSock()
{
}
CServerSock::~CServerSock()
{
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CServerSock, CSocket)
//{{AFX_MSG_MAP(CServerSock)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// CServerSock member functions
extern CCVoiceChatDlg *pDlg;
void CServerSock::OnAccept(int nErrorCode)
{
//if(pDlg->m_firstsock==false)
//{
//pDlg->Contrlsock = new CServerSock;
//}
Accept(*(pDlg->Contrlsock));
// 错误信息处理
if (0 != nErrorCode)
{
switch( nErrorCode) //nErrorCode 为错误码
{
case WSANOTINITIALISED:
AfxMessageBox("A successful AfxSocketInit must occur before using this API.\n");
break;
case WSAENETDOWN:
AfxMessageBox("The Windows Sockets implementation detected that the network subsystem failed.\n");
break;
case WSAEFAULT:
AfxMessageBox("The lpSockAddrLen argument is too small.\n");
break;
case WSAEINPROGRESS:
AfxMessageBox("A blocking Windows Sockets call is in progress.\n");
break;
case WSAEINVAL:
AfxMessageBox("Listen was not invoked prior to accept.\n");
break;
case WSAEMFILE:
AfxMessageBox("The queue is empty upon entry to accept and there are no descriptors available.\n");
break;
case WSAENOBUFS:
AfxMessageBox("No buffer space is available.\n");
break;
case WSAENOTSOCK:
AfxMessageBox("The descriptor is not a socket.\n");
break;
case WSAEOPNOTSUPP:
AfxMessageBox("The referenced socket is not a type that supports connection-oriented service.\n");
break;
case WSAEWOULDBLOCK:
AfxMessageBox("The socket is marked as nonblocking and no connections are present to be accepted. \n");
break;
default:
TCHAR szError[256];
wsprintf(szError, "OnAccept error: %d", nErrorCode);
AfxMessageBox(szError,MB_ICONINFORMATION | MB_OK,NULL);
break;
}
}
pDlg->OnAccept();
CSocket::OnAccept(nErrorCode);
}
void CServerSock::OnConnect(int nErrorCode)
{
CSocket::OnConnect(nErrorCode);
}
void CServerSock::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
pDlg->SerRecvCtrlnfo();
CSocket::OnReceive(nErrorCode);
}
void CServerSock::OnSend(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
CSocket::OnSend(nErrorCode);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -