system C Language

简介: system C Language
#include<Winsock2.h>
#pragma comment(lib,"ws2_32.lib")


Winsock编程接口是微软提供的api


调用winsock函数之前必须装载winsock库,否则会返回socket_error

调用wsaStartup函数初始化wsa

int WSAStartup(WORD wVersionRequested,     //指定winsock加载winsock库的版本
LPWSADATA lpWSAData    //保存WSAStartup函数返回的Winsock库的版本信息
);
//此函数调用成功返回0,失败可调用WSAGetLastError函数确定原因
WSADATA wsaData;
WORD sockVersion=MAKEWORD(2,2);
if(WSAStartup(sockVersion,&wsaData)!=0)
return 0;


Socket函数的原型:

SOCKET socket(
int af,   //用来指定套接字使用的地址格式,这里只能用AF_NET
int type,   //指定套接字的类型
int protocol   //指定协议类型
);

函数调用成功返回一个新的socket句柄,失败返回INVALID_SOCKET


套接字类型:

SOCK_STREAM:流套接字,使用TCP提供有连接的可靠传输

SOCK_DGRAW:数据包套接字,使用UDP提供无连接的不可靠的传输

SOCK_RAW:原始套接字

协议类型:使用TCP通信用TCP,使用UDP通信用IPPROTO_UDP


句柄:一个long型的数据,它是windows用来标识被应用程序所建立或使用的对象的唯一整数


详情请看:http://www.wuchuimeng.com/37.html

目录
相关文章
java.lang.Error: Unresolved compilation problem: The type List is not generic; it cannot be parame
java.lang.Error: Unresolved compilation problem: The type List is not generic; it cannot be parame
|
API
JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Invalid escape sequence at line
JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Invalid escape sequence at line
164 0
|
开发框架 .NET C#
【C#】Language_Integrated_Query——LINQ
欢迎来到本篇LINQ教程,本文介绍了如何使用C#中的LINQ(Language Integrated Query)。LINQ是C#中的功能,可用于从集合中检索,过滤和操作数据。
|
应用服务中间件 Android开发
a configuration error occurred during startup. place verify the preference field whth the prompt:TomcatJDK name:
a configuration error occurred during startup. place verify the preference field whth the prompt:TomcatJDK name:
145 0
a configuration error occurred during startup. place verify the preference field whth the prompt:TomcatJDK name:
|
机器学习/深度学习 测试技术 Python
PAT (Basic Level) Practice (中文)第1002题
PAT (Basic Level) Practice (中文)第1002题
121 0
成功解决Exception: Graph file doesn't exist, path=F:\File_Python\Python_example\Human_Posture_Detection\
成功解决Exception: Graph file doesn't exist, path=F:\File_Python\Python_example\Human_Posture_Detection\
PAT (Advanced Level) Practice - 1129 Recommendation System(25 分)
PAT (Advanced Level) Practice - 1129 Recommendation System(25 分)
110 0
PAT (Advanced Level) Practice - 1055 The World‘s Richest(25 分)
PAT (Advanced Level) Practice - 1055 The World‘s Richest(25 分)
116 0
PAT (Advanced Level) Practice - 1082 Read Number in Chinese(25 分)
PAT (Advanced Level) Practice - 1082 Read Number in Chinese(25 分)
105 0
成功解决Exception: Graph file doesn't exist, path=F:\File_Python\Python_example\Human_Posture_Detection\
成功解决Exception: Graph file doesn't exist, path=F:\File_Python\Python_example\Human_Posture_Detection\