当前位置:网站首页>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 ofIPC
methods ( 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_xxx
andPF_xxx
Is the corresponding .
usePF_xxx
Such a value to createsocket
, useAF_xxx
Such a value to constructsocket
The 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
domain
Specifies the protocol family . Address families are also specified , namely socket Address type of .type
Specifies the communication semantics .protocol
Specify the specific communication protocol .
边栏推荐
- Over fitting and regularization
- Reader writer model
- Hang wait lock vs spin lock (where both are used)
- Remote upgrade afraid of cutting beard? Explain FOTA safety upgrade in detail
- Maximum number of "balloons"
- Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
- Codeforces Round #732 (Div. 2) D. AquaMoon and Chess
- Find a good teaching video for Solon framework test (Solon, lightweight application development framework)
- Developing desktop applications with electron
- SAP-修改系统表数据的方法
猜你喜欢
剑指 Offer 05. 替换空格
Palindrome (csp-s-2021-palin) solution
【Jailhouse 文章】Jailhouse Hypervisor
Educational Codeforces Round 116 (Rated for Div. 2) E. Arena
AtCoder Grand Contest 013 E - Placing Squares
游戏商城毕业设计
EOJ 2021.10 E. XOR tree
To be continued] [UE4 notes] L4 object editing
智慧工地“水电能耗在线监测系统”
Using HashMap to realize simple cache
随机推荐
动漫评分数据分析与可视化 与 IT行业招聘数据分析与可视化
Haut OJ 1316: sister choice buys candy III
Light a light with stm32
Add level control and logger level control of Solon logging plug-in
卷积神经网络——卷积层
In this indifferent world, light crying
Sword finger offer 05 Replace spaces
第六章 数据流建模—课后习题
Add level control and logger level control of Solon logging plug-in
搭建完数据库和网站后.打开app测试时候显示服务器正在维护.
Warning using room database: schema export directory is not provided to the annotation processor so we cannot export
剑指 Offer 53 - II. 0~n-1中缺失的数字
Codeforces Round #716 (Div. 2) D. Cut and Stick
Pointnet++的改进
R语言【数据集的导入导出】
A misunderstanding about the console window
CF1637E Best Pair
Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
Double pointer Foundation
Pointnet++学习