VS2017,MFC,TCP通信,客户端无法连接调试助手

#1.自己所创建的客户端无法连接调试助手。
自己创建的客户端可以和自己创建的服务器端通信,调试助手连不了自己创建的服务器,自己创建的客户端也连不了调试助手。完全不知道问题出在哪了,,
两个客户端可以同时运行,端口和IP使用情况如下:
图片说明

#2.客户端核心代码如下:
##“连接”按钮的时间处理程序。

        void CGeoDlg::OnBnClickedButton1()
        {
            // TODO: 在此添加控件通知处理程序代码
            char ipaddress[35];
            char port[8];
            m_ipaddr.GetWindowText(ipaddress,30);
            cli.sin_addr.s_addr = inet_addr(ipaddress);
            cli.sin_family = AF_INET;
            cli.sin_port = m_ter.GetWindowText(port,8);
            //htons(5000);
            //创建socket
            clisock = socket(AF_INET, SOCK_STREAM, 0);  
            //启动线程
            ee = 1;
            AfxBeginThread(thread, 0);
    }

##线程AfxBeginThread()代码如下

UINT thread(LPVOID v)
{
    char buff[100];
    char array[25][30] =
    { "155.245.160.151",
    "155.245.160.152",
    "155.245.160.153",
    "155.245.160.154",
    "155.245.160.155",
    "155.245.160.156",
    "155.245.160.157",
    "155.245.160.158",
    "155.245.160.159",
    "155.245.160.160",
    "155.245.160.161",
    "155.245.160.162",
    "155.245.160.163",
    "155.245.160.164",
    "155.245.160.165",
    "155.245.160.166",
    "155.245.160.167",
    "155.245.160.168",
    "155.245.160.169",
    "155.245.160.170",
    "155.245.160.171",
    "155.245.160.172",
    "155.245.160.173",
    "155.245.160.174",
    "155.245.160.171" };
    /*CSize size;
    size.cx = 0;
    size.cy = 30;*/
    int s = 1, addcount = 0;
    CGeoDlg *dlg = (CGeoDlg*)AfxGetApp()->GetMainWnd();
    dlg->m_connect.EnableWindow(FALSE);
    dlg->m_disconnect.EnableWindow(TRUE);
    //连接到服务器
    while (connect(dlg->clisock, (sockaddr*)&(dlg->cli), sizeof(dlg->cli)) && dlg->ee != 0)
    {
        dlg->m_edit.SetWindowText("等待.....");
        //空循环
        for (int i = 0; i <= 65000; i++)
            for (int j = 0; j <= 200; j++);
                if (addcount == 25)
                    addcount = 0;
        dlg->cli.sin_addr.s_addr = inet_addr(array[addcount++]);
}

if (dlg->ee == 1)
    dlg->m_edit.SetWindowText( "连接成功");
//dlg->m_button1.EnableWindow(TRUE);
    dlg->SetForegroundWindow();

//循环获得数据
/*while (s != SOCKET_ERROR && dlg->ee != 0)
{
    //调用recv函数接收数据
    s = recv(dlg->clisock, buff, 100, 0);
    dlg->SetForegroundWindow();
    if (s != SOCKET_ERROR && dlg->ee != 0)
        dlg->m_list.InsertItem(dlg->count++, buff);
    dlg->m_list.Scroll(size);
}*/
//发送断开命令
send(dlg->clisock, "Disconnected", 100, 0);
//dlg->m_button1.EnableWindow(FALSE);
dlg->m_connect.EnableWindow(TRUE);
dlg->m_disconnect.EnableWindow(FALSE);
closesocket(dlg->clisock);
AfxEndThread(0);
return 0;
}

#3.完全不知到问题在哪
非计算机类专业,当时也没认真学,现在急着解决问题,实在不知道该怎么办了,,,

c++
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐