当前位置:网站首页>网路编程_socket返回值
网路编程_socket返回值
2022-08-09 02:54:00 【joker_0030】
#include<stdio.h>
#include<stdlib.h>
#include<WinSock2.h>//网络库。<WinSock.h>
#pragma comment(lib,"Ws2_32.lib")//只有32位的。<Wsock32.lib>对应<WinSock.h>库。
int main(void)
{
WORD wdVersion = MAKEWORD(2,2);//传入MAKEWORD宏里,存入wdVersion里。
//MAKEWORD:原理((WORD)(((BYTE)(((DWORD_PTR)(a))&0xff))| ((WORD)(((BYTE)(((DWORD_PTR)(b)) &0xff)))<<8))。
WSADATA wdScokMsg;
//LPWSADATA lpw = malloc(sizeof(WSADATA));
//int a = *((char*)&wdVersion);
//int b = *((char*)&wdVersion+1);
//WSAStartup(wdVersion, lpw);
int nRes=WSAStartup(wdVersion,&wdScokMsg);
if (0!=nRes)
{
switch (nRes)
{
case WSASYSNOTREADY:
printf("重启下电脑试试,或者检查网络库。\n");
break;
case WSAVERNOTSUPPORTED:
printf("请更新网络库。\n");
break;
case WSAEINPROGRESS:
printf("请重新启动软件。\n");
break;
case WSAEPROCLIM:
printf("请尝试关掉不必要的软件,以为当前网络运行提供充足的资源。\n");
break;
/*case WSAEFAULT://参数问题。
break;*/
}
}
//校验版本。
if (2 != HIBYTE(wdScokMsg.wVersion) || 2 != LOBYTE(wdScokMsg.wVersion))
{
//说明版本不对。
//清理网络库。
WSACleanup();
return 0;
}
SOCKET socketServer = socket(AF_INET, SOCK_STREAM,12);
//成功返回可用的socket。失败返回INVALID_SOCKET。
//int a = WSAGetLastError();//检测最近的系统定义函数。
if (INVALID_SOCKET==socketServer)
{
int a = WSAGetLastError();//检测最近的系统定义函数。值为10043,请求的协议还没有在系统中配置,或者没有它存在的迹象。
//创建失败。
//清理网络库。
WSACleanup();
return 0;
}
closesocket(socketServer);
//清理网络库。
WSACleanup();
//free(lpw);
system("pause");
return 0;
}
边栏推荐
猜你喜欢
随机推荐
二分搜索法和二叉搜索树
让历史文化“活”起来,北京河图“万象中轴”助力打造北京城市金名片
unshift() :将一个或多个元素添加到数组的开头
概率模型校准
Kubernetes:(十五)PV与PVC的《恩怨情仇》
普通人如何增加收入
Likou Brush Question Record 3.1-----977. Square of ordered array
Processing Point Clouds
【剑指offer】二进制中1的个数&&2的幂
【网络教程】IPtables官方教程--学习笔记3
【Untitled】
腾讯地图获取定位
What are the most popular automated testing tools in 2022?The most complete and most detailed of the entire network is here
使用TensorRT对AlphaPose模型进行加速
grafana的panel点击title,没有反应,没有出现edit选项
20220524搜索和排序:搜索二维矩阵II
Financial Industry Software Testing Interview Questions (with Answers) | Getting Started Guide
20220527动态规划:零钱兑换
20220523搜索和排序:搜索旋转排序数组
Building PO layered architecture of automated testing framework from 0








