当前位置:网站首页>Simply sort out the types of sockets
Simply sort out the types of sockets
2022-07-05 05:35:00 【Raise items】
List of articles
After this period of time to learn network programming , I found that there are many types of sockets , Not only
TCP and UDP So simple , This article is simple socket The type of . socket system call
adopt establish socket The system call interface of can see the kernel pair socket The classification of .
// #include <sys/socket.h>
int socket(int domain, int type, int protocol);
Parameters
adopt domain、type and protocol These three parameters can only Identify a socket. So it's OK to socket do Three dimensions The classification of .
domain
This parameter specifies Protocol family . There are several values in total :
PF_LOCAL Host-internal protocols, formerly called PF_UNIX,
PF_UNIX Host-internal protocols, deprecated, use PF_LOCAL,
PF_INET Internet version 4 protocols,
PF_ROUTE Internal Routing protocol,
PF_KEY Internal key-management function,
PF_INET6 Internet version 6 protocols,
PF_SYSTEM System domain,
PF_NDRV Raw access to network device,
PF_VSOCK VM Sockets protocols
There are three kinds of commonly used :
PF_INET:ipv4 Type of socket, Use ipv4 network address + Port number identification socket The address of , Used for communication between hosts .PF_INET6:ipv6 Type of socket, Use ipv6 network address + Port number identification socket The address of , Used for communication between hosts .PF_LOCAL: Local socket, Use The absolute pathname of a file identification socket Address , Used between different processes on the same host , It's a kind ofIPCmethods ( It is equivalent to two processes passing Share a file Achieve communication ). The socket It uses Simplified network protocol stack , So the performance is high .
The protocol family determines , The address family is determined .
structure socket The address of when , To specify Address family (AF_xxx),AF_xxxandPF_xxxIs the corresponding .
usePF_xxxSuch a value to createsocket, useAF_xxxSuch a value to constructsocketThe address of .
type
This parameter specifies Semantics of communication . There are three values :
SOCK_STREAM
SOCK_DGRAM
SOCK_RAW
SOCK_STREAM: Byte stream type , Provide Orderly 、 reliable 、 There is a connection 、 Based on byte stream Communication mechanism .SOCK_DGRAM: Datagram type , Provide The maximum length is fixed 、 There is no connection 、 unreliable Communication mechanism .SOCK_RAW: original socket type , Provide right Internal network protocols and interfaces The interview of , Available only for super users . Raw socket It can be handled without the network protocol stack , Direct access to the network card , Send the message constructed by the user process .
protocol
This parameter specifies socket The specific protocol to be used in communication .
When the first two parameters Cannot uniquely identify One Specific network communication protocol when , Will use protocol Specify a specific agreement .
Return value
This function returns a socket The descriptor , Return... On failure -1.
stay Linux Inside , Everything is a document ,socket No exception .
socket system call <----> open system call
socket The descriptor <----> File descriptor
adopt socket send data <----> The document says
adopt socket receive data <----> File read
summary
domainSpecifies the protocol family . Address families are also specified , namely socket Address type of .typeSpecifies the communication semantics .protocolSpecify the specific communication protocol .
边栏推荐
- MySQL数据库(一)
- [jailhouse article] look mum, no VM exits
- Service fusing hystrix
- Pointnet++ learning
- 第六章 数据流建模—课后习题
- Demonstration of using Solon auth authentication framework (simpler authentication framework)
- Graduation project of game mall
- Sword finger offer 35 Replication of complex linked list
- R语言【数据集的导入导出】
- 【实战技能】非技术背景经理的技术管理
猜你喜欢
![[to be continued] [UE4 notes] L1 create and configure items](/img/20/54ba719be2e51b7db5b7645b361e26.jpg)
[to be continued] [UE4 notes] L1 create and configure items

Sword finger offer 35 Replication of complex linked list

全国中职网络安全B模块之国赛题远程代码执行渗透测试 //PHPstudy的后门漏洞分析

2017 USP Try-outs C. Coprimes

Chapter 6 data flow modeling - after class exercises

Sword finger offer 06 Print linked list from beginning to end

剑指 Offer 09. 用两个栈实现队列

CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five

Improvement of pointnet++

CF1634E Fair Share
随机推荐
Codeforces Round #716 (Div. 2) D. Cut and Stick
剑指 Offer 58 - II. 左旋转字符串
Kubedm series-00-overview
常见的最优化方法
每日一题-无重复字符的最长子串
Haut OJ 1347: addition of choice -- high progress addition
Warning using room database: schema export directory is not provided to the annotation processor so we cannot export
Haut OJ 1401: praise energy
[jailhouse article] jailhouse hypervisor
Control Unit 控制部件
F - Two Exam(AtCoder Beginner Contest 238)
Demonstration of using Solon auth authentication framework (simpler authentication framework)
剑指 Offer 05. 替换空格
Fried chicken nuggets and fifa22
To be continued] [UE4 notes] L4 object editing
Sword finger offer 35 Replication of complex linked list
Sword finger offer 06 Print linked list from beginning to end
卷积神经网络简介
High precision subtraction
Haut OJ 1221: a tired day