当前位置:网站首页>Advanced API (UDP connection & map set & collection set)
Advanced API (UDP connection & map set & collection set)
2022-07-03 07:01:00 【Bugxiu_ fu】
.UDP agreement :
DatagramSocket--- This object can represent the receiving end or the sending end
DatagramPacket----- Data packaging objects ( Datagram objects -- Package the sent content through this object , Transfer the object through the specified method )
1. adopt DatagramSocket Create sender object
* 2. Prepare the data
* 3. adopt DatagramPacket Do data packaging
* 4. Call the method of sending content through the sending end object
* 5. close resource
UDP protocol ( There is no connection )
(1) Put the data 、 Source 、 The purpose is encapsulated in packets , No connection needed
(2) The size of each datagram is limited to 64K Inside ( Send as a container )
(3) Send whether the other party is ready or not , The receiving party does not acknowledge the receipt , Therefore, it is unreliable
(4) It can be broadcast
(5) There is no need to release resources at the end of sending data , Low overhead , Fast
The basic format :
1. Create the receiver && The sender
DatagramSocket ds = new DatagramSocket(8989);
2. Prepare the data
String content = " floret , Let's watch a movie tonight .";
3. Create datagram objects
DatagramPacket dp = null;
4. Call the method of sending content through the sending end object
db=new DatagramPacket(buf, length, address, port)
buf Sent content content.getBytes()
length The size of the content content.getBytes().length
address Send the specified receiving end (IP Address )InetAddress.getByName("127.0.0.1")
port Port number 8989
5. receive && Send method to activate
ds.receive(dp);// receive
ds.send(dp);// send out
close resource
ds.close();
Collection aggregate :
ArrayList|LinkedList|Vector
List<String> list = new ArrayList<String>();
Method :
// list.add("agds");
// size()
// clear
// get
// contains
// isEmpty
// remove
Map aggregate :
A two column set can be added at one time 2 Data
Stored data is stored in the form of key value pairs
Key is unique Values can be repeated
Common implementation classes HashMap
List|Set
List: Orderly Element repeatable
Set: disorder only
String key = next.getKey();// key
String Value=new.getValue;// value
1. Create a Map aggregate
Map map = new HashMap();
2. Calling method
newly added
map.put(" Yang2 guo4 ", " Steamed Dumplings ");
map.put(" Peng Yong ", " Cui Hua ");
map.put(" Lao Wang ", " Xiong Mei ");
map.put(" Tang Ye ", " Widow Wang ");
map.put(" yoga ", " Widow Wang ");
// size
System.out.println(map.size());//5
//clear Empty
map.clear();
System.out.println(map.size());
// Determines if the set is empty
System.out.println(map.isEmpty());
map Collection call entrySet Methods will map The key value pairs in the collection are encapsulated into Entry The entity object returns Set aggregate
Set<Entry<String, String>> entrySet = map.entrySet();
//set Traversal by iterator
Iterator<Entry<String, String>> iterator = entrySet.iterator();
while(iterator.hasNext()) {
Entry<String, String> next = iterator.next();
System.out.println(next.getKey()+"--"+next.getValue());
}
边栏推荐
- Unittest attempt
- Book recommendation~
- What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
- Sorting out the core ideas of the pyramid principle
- Know flex box
- php artisan
- MySQL transaction rollback, error points record
- Split small interface
- Climb movie paradise 2021 hot
- These two mosquito repellent ingredients are harmful to babies. Families with babies should pay attention to choosing mosquito repellent products
猜你喜欢

Mise en place d'un environnement de développement de fonctions personnalisées

dataworks自定義函數開發環境搭建

如何迁移或复制VMware虚拟机系统

How to migrate or replicate VMware virtual machine systems

Inno setup production and installation package
![[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones](/img/d0/850e095a43610366d6144b2471f3f7.jpg)
[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones

Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
![[untitled]](/img/72/4ff9354634342580a135debb58b60e.jpg)
[untitled]

Ruoyi interface permission verification
![[classes and objects] explain classes and objects in simple terms](/img/41/250457530880dfe3728432c2ccd50b.png)
[classes and objects] explain classes and objects in simple terms
随机推荐
这两种驱蚊成份对宝宝有害,有宝宝的家庭,选购驱蚊产品要注意
JS date comparison
Laravel Web Framework
修改MySQL密码
IC_EDA_ALL虚拟机(丰富版):questasim、vivado、vcs、verdi、dc、pt、spyglass、icc2、synplify、INCISIVE、IC617、MMSIM、工艺库
My 2020 summary "don't love the past, indulge in moving forward"
机器学习 | 简单但是能提升模型效果的特征标准化方法(RobustScaler、MinMaxScaler、StandardScaler 比较和解析)
Pytest -- write and manage test cases
Laravel框架 踩坑(一)
利用C#实现Pdf转图片
Practice of enterprise ab/testing platform
Operation principle of lua on C: Foundation
UTC time, GMT time, CST time
Hands on redis master-slave replication, sentinel master-slave switching, cluster sharding
Advanced API (use of file class)
Notes on the core knowledge of Domain Driven Design DDD
Asynchronous programming: async/await in asp Net
JMeter test result output
dataworks自定义函数开发环境搭建
Golang operation redis: write and read kV data