当前位置:网站首页>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());
}
边栏推荐
- Software testing learning - day 3
- These two mosquito repellent ingredients are harmful to babies. Families with babies should pay attention to choosing mosquito repellent products
- Summary of the design and implementation of the weapon system similar to the paladin of vitality
- How to migrate or replicate VMware virtual machine systems
- Setting up the development environment of dataworks custom function
- Summary of UI module design and practical application of agent mode
- Pytest attempts to execute the test case without skipping, but the case shows that it is all skipped
- The 10000 hour rule won't make you a master programmer, but at least it's a good starting point
- Strategy mode
- Pits encountered in the use of El checkbox group
猜你喜欢

Jenkins

Application scenarios of Catalan number

Pits encountered in the use of El checkbox group

每日刷題記錄 (十一)

Practical plug-ins in idea

vmware虚拟机C盘扩容

New knowledge! The virtual machine network card causes your DNS resolution to slow down

How to migrate or replicate VMware virtual machine systems

Golang operation redis: write and read kV data

Summary of UI module design and practical application of agent mode
随机推荐
Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
卡特兰数(Catalan)的应用场景
Dbnet: real time scene text detection with differentiable binarization
Tool class static method calls @autowired injected service
Upgrade CentOS php7.2.24 to php7.3
Book recommendation~
POI excel percentage
Sorting out the core ideas of the pyramid principle
JS date comparison
In depth analysis of reentrantlock fair lock and unfair lock source code implementation
Resttemplate configuration use
How to plan well?
The 10000 hour rule won't make you a master programmer, but at least it's a good starting point
CentOS php7.3 installing redis extensions
Software testing learning - the next day
What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
Architecture notes
2022-06-23 VGMP-OSPF-域间安全策略-NAT策略(更新中)
[LeetCode]404. Sum of left leaves
mongodb