VC中socket编程中recv()运行不了,求解!!!
{ WSADATA wsaData;
//初始化Socket库
WSAStartup(MAKEWORD(2,0),&wsaData);
//创建一根电线
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
SOCKADDR_IN sa;
sa.sin_family=AF_INET;
//设置电线连接服务器端的端口 www.time.国家授时中心
sa.sin_port = htons(IPPORT_TIMESERVER);//授时服务器是37端口IPPORT_TIMESERVER。210.72.145.8
sa.sin_addr.S_un.S_addr = inet_addr("210.72.145.8"); //Time.nist.gov 192.43.244.18
//为什么不用设置客户端的端口,难道不需要客户端的端口吗?(一般为动态生成!)
if(connect(sock,(SOCKADDR *)&sa,sizeof(sa))==SOCKET_ERROR)
{
MessageBox(NULL,TEXT("连接失败!!!"),"",MB_ICONERROR);
ShowError();
return;
}
MessageBox(NULL,TEXT("连接成功!!!"),"",MB_OK); ////////////测试用
TCHAR buff[256];
ZeroMemory(buff,sizeof(buff)/sizeof(TCHAR));
unsigned long ulTime=-999990;
MessageBox(NULL,buff,TEXT("1"),MB_OK);/////////////此句还可以运行!!!!测试用
recv(sock,(char *)&ulTime,sizeof(unsigned long),0);/////////////此句运行有问题!!!!
MessageBox(NULL,buff,TEXT("2"),MB_OK);/////////////此句已不能运行!!!!测试用
wsprintf(buff,"%i",ulTime);
closesocket(sock);
WSACleanup();
}
当程序执行到:【recv(sock,(char *)&ulTime,sizeof(unsigned long),0);/////////////此句运行有问题!!!!】时,
程序就走不了了,在网上搜说是socket阻塞,可我不懂。。。急急急!!!