大家好,我想做个socket连接上服务器端。下面是那主要的代码,错误是没有的,但是socket好像连不上。
希望大家能帮帮我,看出了什么问题?谢谢
void CTestFtpDlg::OnSubmit()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_list.AddString(\"欢迎使用FTPTranser多线程,断点续传软件!!\");
SOCKADDR_IN sockStruct;sockStruct.sin_family = AF_INET;
sockStruct.sin_port = htons(21);
memcpy(&(sockStruct.sin_addr),\"192.168.15.16\",sizeof(int));
SOCKET sct = socket(PF_INET,SOCK_STREAM,0);
connect(sct,(LPSOCKADDR)&sockStruct,sizeof(sockStruct));
char * buffer = new char[100];
int recLen ;
recLen = recv(sct,buffer,100,0);
buffer[recLen]=0;
m_list.AddString(buffer);CString user = \"USER member \r\n\";
m_list.AddString(\"发送用户名...\");
send(sct,user,user.GetLength(),0);
//接收响应
recLen = recv(sct,buffer,100,0);
buffer[recLen]=0;
m_list.AddString(GetCode(buffer));if(GetCode(buffer) == \"331\")
{
m_list.AddString(\"服务器要求验证密码。\");
CString password = \"PASS haha \r\n\";
this->m_list.AddString(\"发送密码...\");
send(sct,password,password.GetLength(),0);
recLen = recv(sct,buffer,100,0);
if(GetCode(buffer) == \"230\")
{
m_list.AddString(\"success\");
}
}
UpdateData(false);
}