我有如下代码:
if (!AfxSocketInit())
{
AfxMessageBox("IDP_SOCKETS_INIT_FAILED");
}
int nPort=5000;
pSocket->Create(nPort);
CString strText;
strText="ss";
pSocket->Send(strText,2);
用于客户端,该代码正常执行时,用服务端程序连接5000这个端口,连接失败,为什么?
if (!AfxSocketInit())
{
AfxMessageBox("IDP_SOCKETS_INIT_FAILED");
}
int nPort=5000;
pSocket->Create(nPort);
CString strText;
strText="ss";
pSocket->Send(strText,2);
用于客户端,该代码正常执行时,用服务端程序连接5000这个端口,连接失败,为什么?
//服务器端
CSocket Server;
Server.Create(5000);
Server.Listen();
//重载OnAccept()
CSocket Communicate;
Accept(Communicate);
//以后可是使用Communicate进行通讯.
//////////////////////////////////
//客户端
CSocket client;
client.Create();
if(!client.Connect(strServerName)
{
::MessageBox(NULL,"连接失败",NULL,MB_OK);
return FALSE;
}
client.Send(strText,strText.GetLength());
I dont think so.>>用于客户端,该代码正常执行时,用服务端程序连接5000这个端口,连接失败,为什么?
that's could be port_reuse problem.
if in both s/c side you have the similar code like:
pSocket->Create(nPort);If the problem still exist.
So,Use GetLastError() to get the error code and post it out.