服务器端:
void CFileServDlg::Onbtnlisten() 
{
// TODO: Add your control notification handler code here
CSocket sockserv;
sockserv.Create(800);
CSocket sockconn;
sockserv.Accept(sockconn);

}
客户端:
void CFileClientDlg::Onbtnconnect() 
{
// TODO: Add your control notification handler code here
AfxSocketInit(NULL);
CSocket sockcli;
sockcli.Create();
CString szIP;
GetDlgItemText(IDC_EDIT_IPADDRESS,szIP);
if(sockcli.Connect((LPCTSTR)szIP,800))
{
AfxMessageBox("Connect successfully!");
return;
}
else
{
CString str;
str.Format("Error code:%d",CSocket::GetLastError());
AfxMessageBox("connect fail!\n"+str);
return;
}

}

解决方案 »

  1.   

    可以用FormatMessage格式化错误信息看一下。
      

  2.   

    WSAECONNREFUSED
    10061 
    Connection refused. 
    No connection could be made because the target computer actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host—that is, one with no server application running.  
    --------------
    看不出来程序哪里错了,换端口也不行。
      

  3.   

    No connection could be made because the target machine actively refused it.
      

  4.   

    我晕了,我居然落了listen.......