18,356
社区成员
发帖
与我相关
我的任务
分享
USES_CONVERSION;
char *IPC = T2A(IPaddress), *PortC = T2A(Port);
int tPort = atoi(PortC);
Main->addrC.sin_family = AF_INET;
Main->addrC.sin_port = htons(tPort);
Main->addrC.sin_addr.S_un.S_addr = inet_addr(IPC);
::connect(Main->Csock, (sockaddr*)&(Main->addrC), sizeof(Main->addrC));
fd_set wfd;
struct timeval timeout;
FD_ZERO(&wfd);
timeout.tv_sec = 10;
timeout.tv_usec=0;
FD_SET(Main->Csock, &wfd);
int Res = 1;
Res = select(1, NULL, &wfd, NULL, &timeout);
if (Res == 0 || Res == SOCKET_ERROR)
{
CString temp;
int n = WSAGetLastError();
temp.Format(L"连接失败!请重试!错误%d", n);
MessageBox(temp);
}
else
{
MessageBox(L"连接成功!");
CDialogEx::OnOK();
}