初始化Windows Sockets

代码来源:《Windows网络编程》(罗莉琴,詹祖桥 主编)(如造成任何不便,请联系我删除)

#include "stdafx.h"

#include 
#pragma comment(lib,"ws2_32.lib")
#include 


int _tmain(int argc, _TCHAR* argv[])
{
	//WSADATA结构体主要包含了系统所支持的Winsock版本信息
	WSADATA wsaData;
	//初始化Winsock 2.2
	if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
	{
		printf("WSAStartup 无法初始化!");
		return 0;
	}
	//显示wsaData中的数据
	printf("Version: %d.%d\n",LOBYTE(wsaData.wVersion),HIBYTE(wsaData.wVersion));
	printf("High Version: %d.%d\n", LOBYTE(wsaData.wHighVersion), HIBYTE(wsaData.wHighVersion));
	printf("Description: %s\n",wsaData.szDescription);
	printf("System Status: %s\n",wsaData.szSystemStatus);

	//清除工作
	if (WSACleanup() == SOCKET_ERROR)
	{
		printf("WSACleanup 出错!");
	}

	system("pause");
	return 0;
}


 

你可能感兴趣的:(网络编程)