64,648
社区成员
发帖
与我相关
我的任务
分享
OutputDebugString("等待网络接入线程开始: ");
CDibblingDlg* pThis = (CDibblingDlg*)lParam;
SOCKET _sLocal = NULL;
if(_sLocal = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) == SOCKET_ERROR)
{
AfxMessageBox("网络异常,请检查网络连接!");
return -1;
}
CString _cPort;
pThis->m_edPort.GetWindowText(_cPort);
int nPort = atoi(_cPort);
sockaddr_in _InternetAddr;
ZeroMemory(&_InternetAddr, sizeof(_InternetAddr));
_InternetAddr.sin_family = AF_INET;
_InternetAddr.sin_port = htons(nPort);
_InternetAddr.sin_addr.S_un.S_addr = htonl(INADDR_ANY);
if(bind(_sLocal, (struct sockaddr*)&_InternetAddr, sizeof(_InternetAddr)) == SOCKET_ERROR)
{
AfxMessageBox("网络异常,请检查网络连接!");
return -1;
}
if(listen(_sLocal, 5) == SOCKET_ERROR)
{
AfxMessageBox("网络异常,请检查网络连接!");
return -1;
}