程序运行后无法连接上
void CClientDlg::OnConnbutton() 
{
// TODO: Add your control notification handler code here
UpdateData(true); m_ClientSocket.Create();
if(m_ClientSocket.Connect(m_strIP,m_nPort))
AfxMessageBox("Connect the Server Successful!");
else
AfxMessageBox("Connect the Server Failed!");}
运行后出现Connect the Server Failed这样的弹出对话框,

解决方案 »

  1.   

    create() 函数怎么没有参数呢你的。写上参数亚。
      

  2.   

    先确定服务器是否启动,监听端口是否正确
    然后检查
    if (!AfxSocketInit())
    {
    AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
    return FALSE;
    }
    是否初始化Socket
      

  3.   

    IP.port.你确信server开了?
    ..这个类没有用过.要不要指定是tcp还是udp啊?
      

  4.   

    我是新手,请多指教:
    我是在同一台机器上实现信息传送的,psprite(小皮)
    先确定服务器是否启动,监听端口是否正确
    然后检查
    if (!AfxSocketInit())
    {
    AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
    return FALSE;
    }
    是否初始化Socket的解释不明白,能详细些吗?  
     
      

  5.   

    void CClientDlg::OnConnbutton()
    {
    // TODO: Add your control notification handler code here
    UpdateData(true);m_ClientSocket.Create();
    if(m_ClientSocket.Connect(m_strIP,m_nPort))
    AfxMessageBox("Connect the Server Successful!");
    else
    AfxMessageBox("Connect the Server Failed!");}
    把这段代码改为
    void CClientDlg::OnConnbutton()
    {
    // TODO: Add your control notification handler code here
    UpdateData(true);m_ClientSocket.Create();
    if(m_ClientSocket.Connect(m_strIP,m_nPort))
    AfxMessageBox("Connect the Server Successful!");
    else
    {
    AfxMessageBox("Connect the Server Failed!");
    TRACE1("error code = %d\n",GetLastError());
    }
    }
    调试程序看看error code是多少就知道原因啦.
      

  6.   

    用MFC时,要在创建的过程中选中“使用SOCKET支持”之类的提示的选项,就会自动运行
    if (!AfxSocketInit())
    {
    AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
    return FALSE;
    }
    这个东西了。建一个类:class CMySvr : public CSocket{。}
           用CTRL+W建立起来。CClientDlg里要定义一个SOCKET对象: 
         CMySvr *m_pSockSvr;最后:
    m_pSockSvr = new CMySvr();     //创建对象
             UINT nPortSvr = 50000;
    if (m_pSockSvr->Create(nPortSvr))
    {
    Listen();
                       AfxMessageBox("Connect the Server Successful!"); }
    else
                      AfxMessageBox("Connect the Server Failed!");