当前位置:网站首页>Network protocol of yyds dry goods inventory: datagram socket for detailed explanation of socket protocol
Network protocol of yyds dry goods inventory: datagram socket for detailed explanation of socket protocol
2022-06-11 11:38:00 【Procedural stuff】
brief introduction
In the last article we explained Socket Classification and the most commonly used Stream Socket,Stream Socket It's usually based on TCP Agreed , So we are often in web They can be seen in the service . Of course TCP The agreement has a twin brother called UDP, Then based on UDP To do the transmission protocol socket The agreement is called Datagram Socket, Today, let's take a closer look at Datagram Socket.
What is? Datagram Socket
And connected Stream Socket Different ,Datagram Socket It's disconnected . Connected Stream Socket Indicates that the socket It's stable , So we can Stream socket Stable data transmission in , Of course, this stability means that packets will not be lost , But it is not always possible to ensure that the packet is not tampered with .
Datagram Socket This connectionless is usually used in scenarios that allow partial loss of data , Like voice 、 Video and so on , The advantage of no connection is that you don't need TCP The complex steps of establishing a connection , So it's relatively simpler .
Datagram Socket The usual use is UDP Protocol as the underlying data transmission protocol .
about UDP Come on , because UDP The protocol itself does not guarantee the order of data and the handling of data exceptions , These need to be implemented in the application itself .
common UDP Applications include DNS(Domain Name System) service ,NTP(Network Time Protocol) Services, etc. .
stay JDK Of java.net The package provides a pair of Datagram Socket Encapsulation , The state of three connections is defined :
Indicates that no connection has been established , Established connection and established connection , But it hasn't been realized yet level.
in addition , stay DatagramSocket It also contains the address and port of a connection :
Use socat To create UDP service
Be careful , Before using subsequent commands , Need to be in unix Execute the installation command in the environment :yum install iproute2 netcat-openbsd socat
And before Stream Socket equally , We can also use socat command , To build a UDP The server , We need to use socat The following parameters :
We need to monitor udp4 and udp6 The data of , So here we use udp4-listen and udp6-listen Two parameters .
The following port number can be customized , Here we still use the same 8888 port , The corresponding command is as follows :
The command above , We are 8888 Listening on the port UDP4 and UDP6 Connection information , among fork Parameter indicates that the program continues to run after receiving the package , If not fork, Then the program will automatically exit .
socat There was going to be one in the back bi-address, Here we use /dev/null, It means discarding all income Information .
UDP6-LISTEN There is a special parameter called ipv6only, Indicates that the received packet should not be sent to IPv4-mapped IPv6 addresses.
What is? IPv4-mapped IPv6 addresses? Simply put, it means to IPv4 Mapped to IPv6 Address in .
Execute the above command , We will get the following output :
Because it is executed in the background , So we returned to the process ID.
Use ss Command to monitor Datagram Sockets
ss The command can be used to check socket The state of , Here we need to use ss These parameters :
Because we only monitor ipv4 and ipv6 The data of , So here we use -4 and -6 These two parameters .
In addition, because you only need to monitor udp sockets, So we need to use -u Parameters .
Because it's monitoring , So use -l Parameters , Finally, we hope to see specific figures , Instead of being resolved to a service name , So here we use -n Parameters .
Let's use the following command to see the result :
You can get the following results :
The above command only monitors Ipv4, Let's see Ipv6:
You can get the following results :
and Ipv4 It's very similar , It means that we are Ipv6 The supervisor heard the port 8888.
Use nc Establish and UDP Socket The connection of
We've set up a monitor UDP Connected servers , Next we try to use nc Command to connect .
nc yes Ncat For short , Is a very small and efficient network tool . Let's look at the parameters that will be used in this example :
Because you need to connect to Ipv4 and Ipv6, So we need to -4 and -6 Parameters .
By default nc It uses TCP agreement , If you want to use udp You need to use -u This parameter .
In addition, we need to output detailed information , So we need to -v Parameters , Finally, we directly establish the connection , Don't send any data , So here we use -z Parameters , Let's execute it and see the effect :
Look at the output below :
Express UDP Successful connection .
alike , We can use the following command to connect to UDP socket:
among ::1 It represents the local ipv6 Address .
You can get the following results :
Express UDP Successful connection .
summary
This article explains datagram socket Basic concepts of , And use some unix The basic commands to build udp Servers and clients , So that you can understand .
This article has been included in http://www.flydean.com/16-datagram-socket/
The most popular interpretation , The deepest dry goods , The most concise tutorial , There are so many tricks you don't know about waiting for you to discover !
Welcome to my official account. :「 Program those things 」, Know technology , Know you better !
边栏推荐
- Add auto thumbnail function for WordPress related log plug-ins
- Etcd introduction
- Guice integrated properties configuration
- AcWing 1944. 记录保存(哈希,STL)
- WordPress database cache plug-in: DB cache Reloaded
- What is the latest popular annuity insurance product with higher income in 202?
- Smart sidebar plug-in: Mo widgets
- 设置默认收货地址【项目 商城】
- Interview experience of Xiaomi Android development post~
- JS interview questions - arrow function, find and filter some and every
猜你喜欢

李飞飞:我更像物理学界的科学家,而不是工程师|深度学习崛起十年

JS prototype. The find () method has no effect on the object array. It is urgent...

It will be too late if you don't brush the questions. The most complete bat interview questions

Liufan, CFO of papaya mobile, unleashes women's innovative power in the digital age

Enterprise wechat applet pit avoidance guide, welcome to add...

MyCat-分库分表
![Définir l'adresse de réception par défaut [Centre commercial du projet]](/img/eb/2864b124b66d01849315a367948ed4.png)
Définir l'adresse de réception par défaut [Centre commercial du projet]

設置默認收貨地址【項目 商城】

js面试题---箭头函数,find和filter some和every
![Set the default receiving address [project mall]](/img/eb/2864b124b66d01849315a367948ed4.png)
Set the default receiving address [project mall]
随机推荐
【碎碎念】关于波长|波速|周期的想法
MyCat-分库分表
Gerber文件在PCB制造中的作用
在毕设中学习03
Liufan, CFO of papaya mobile, unleashes women's innovative power in the digital age
What is the best annuity insurance product in 2022?
Typeerror: argument of type "Int 'is not Iterable
js中Array.prototype.find() 方法在对象数组上无效果,捉急。。。
Web development model selection, who graduated from web development
JVM class loading process
Don't be a fake worker
js面试题---箭头函数,find和filter some和every
nft数字藏品app系统搭建
AcWing 1944. 记录保存(哈希,STL)
AcWing 1353. 滑雪场设计(贪心)
设置默认收货地址【项目 商城】
WordPress登录页面美化插件:Login Designer推荐
CAP理论听起来很高大上,其实很简单
Collection of practical WordPress plug-ins (under update)
Recommend several gravatar avatar caching plug-ins