swomfs 2017-04-20 02:30 采纳率: 0%
浏览 1266

VS2010 MFC CSocket为什么只能接收到服务器的一次返回的信息,新手求大神详解谢谢

CSocket sock_client;
......
void Cftp_clientDlg::OnBnClickedconnect()
{
AfxSocketInit();
if(!sock_client.Create())
{
AfxMessageBox(_T("socket创建失败!"));
return;
}
UpdateData(true);
if(!sock_client.Connect(m_host,m_port))
{
AfxMessageBox(_T("socket连接服务器失败!"));
return;
}

MySockRecv();

CString send_msg;
send_msg = "USER ";
send_msg += m_name;
send_msg += "\r\n";
MySockSend(send_msg);

MySockRecv();

send_msg = "PASS ";
send_msg += m_password;
send_msg += "\r\n";
MySockSend(send_msg);

MySockRecv();


void Cftp_clientDlg::MySockRecv()
{
char buf_recv[200] = "";
if(SOCKET_ERROR == sock_client.Receive(buf_recv,199))
{
AfxMessageBox(_T("数据接收失败!"));
return;
}
CString show_msg("响应:");
show_msg += buf_recv;
m_listbox.AddString(show_msg);
}
void Cftp_clientDlg::MySockSend(CString send_msg)
{
if(SOCKET_ERROR == sock_client.Send(send_msg,send_msg.GetLength()))
{
AfxMessageBox(_T("数据发送失败!"));
return;
}
CString show_msg("命令:");
show_msg += send_msg;
m_listbox.AddString(show_msg);
}图片说明

  • 写回答

1条回答 默认 最新

  • Strive--顾 2017-04-24 08:53
    关注

    你去网上搜搜csocket服务器客户端编程 会有许多下载资源 你下一个慢慢研究

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog