C程序编译通不过,求助
想写个最简单的socket连接某网址。不需要接收数据,只要触发该网址即可。帮我看看下面的代码有什么问题,visual c++ 6.0通不过。#include <Winsock2.h>
#include <stdio.h>
#pragma comment(lib,"ws2_32.lib")
void main()
{
//加载套接字
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested=MAKEWORD(1,1);
err=WSAStartup(wVersionRequested,&wsaData);
if (err!=0)
{
return;
}
if (LOBYTE(wsaData.wVersion)!=1||
HIBYTE(wsaData.wVersion)!=1)
{
WSACleanup();
return;
}
//创建套接字
SOCKET sockClient=socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr=inet_addr("127.0.0.1");//把U_LONG的主机字节顺序转换为TCP/IP网络字节顺序
addrSrv.sin_family=AF_INET;
addrSrv.sin_port=htons(6000);
//向服务器发送请求
connect(sockClient,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
//接受数据
char recBuf[100];
recv(sockClient,recBuf,100,0);
printf("%s\n",recBuf);
//发送数据
send(sockClient,"this is",strlen("this is")+1,0);
//关闭套接字
closesocket(sockClient);
WSACleanup();
}