当前位置:网站首页>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());
}
边栏推荐
- New knowledge! The virtual machine network card causes your DNS resolution to slow down
- How to migrate or replicate VMware virtual machine systems
- Software testing learning - the next day
- Summary of the design and implementation of the weapon system similar to the paladin of vitality
- Class and object summary
- dataworks自定義函數開發環境搭建
- Advanced API (use of file class)
- Pits encountered in the use of El checkbox group
- Error c2017: illegal escape sequence
- mysql误删root账户导致无法登录
猜你喜欢
2022-06-23 VGMP-OSPF-域间安全策略-NAT策略(更新中)
My 2020 summary "don't love the past, indulge in moving forward"
每日刷題記錄 (十一)
Inno Setup 制作安装包
[set theory] partition (partition | partition example | partition and equivalence relationship)
Reading notes of "learn to ask questions"
Golang operation redis: write and read hash type data
Golang operation redis: write and read kV data
【类和对象】深入浅出类和对象
熊市里的大机构压力倍增,灰度、Tether、微策略等巨鲸会不会成为'巨雷'?
随机推荐
Advanced API (use of file class)
Software testing assignment - day 3
Setting up the development environment of dataworks custom function
Hands on redis master-slave replication, sentinel master-slave switching, cluster sharding
Laravel frame step pit (I)
Pytest attempts to execute the test case without skipping, but the case shows that it is all skipped
JMeter JSON extractor extracts two parameters at the same time
The education of a value investor
Pytest -- write and manage test cases
centos php7.2.24升级到php7.3
机器学习 | 简单但是能提升模型效果的特征标准化方法(RobustScaler、MinMaxScaler、StandardScaler 比较和解析)
How can I split a string at the first occurrence of “-” (minus sign) into two $vars with PHP?
Software testing assignment - day 1
On the practice of performance optimization and stability guarantee
Climb movie paradise 2021 hot
How can the server set up multiple interfaces and install IIS? Tiantian gives you the answer!
Golang operation redis: write and read kV data
Gridome + strapi + vercel + PM2 deployment case of [static site (3)]
Software testing learning - day one
DBNet:具有可微分二值化的实时场景文本检测