关于soctet和多线程的问题,请高手多指教。
我在做一个代理服务器,用多线程,编译通过,运行时产生错误,见源码:
UINT GetRemoteData(LPVOID Pparam);
UINT GetRemoteData(LPVOID Pparam)
{
CProDlg *dlg=(CProDlg *)AfxGetMainWnd();
CSocket Server;
char Buffer[BUFFERSIZE+SERVERNAMEMAXSIZE];
CProxy *client=(CProxy *)Pparam;
int n =client->Receive(Buffer,BUFFERSIZE);
if (n == -1)
return 0;
Buffer[n] = 0;
if (!Server.Create ())
return 0;
.
.
return 0;
}
void CProxy::OnAccept(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
CProDlg *dlg=(CProDlg *)AfxGetMainWnd();
CProxy *Client=new CProxy();
if(Accept(*Client))
AfxBeginThread(GetRemoteData,Client);
else
delete Client;
CSocket::OnAccept(nErrorCode);
}
把 if (!Server.Create ()) return 0; 这一行注释掉,就不会有错,为什么?调试时提示非法指针。