当前位置:网站首页>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());
}
边栏推荐
- [Code] if (list! = null & list. Size() > 0) optimization, set empty judgment implementation method
- [classes and objects] explain classes and objects in simple terms
- Advanced API (character stream & net for beginners)
- JS date comparison
- Machine learning | simple but feature standardization methods that can improve the effect of the model (comparison and analysis of robustscaler, minmaxscaler, standardscaler)
- Pytest attempts to execute the test case without skipping, but the case shows that it is all skipped
- 机械观和系统观的科学思维方式各有什么特点和作用
- 10000小時定律不會讓你成為編程大師,但至少是個好的起點
- 2022-06-23 VGMP-OSPF-域间安全策略-NAT策略(更新中)
- IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library
猜你喜欢

HMS core helps baby bus show high-quality children's digital content to global developers

vmware虚拟机C盘扩容

Software testing assignment - the next day

Interfaces and related concepts

EasyExcel

每日刷题记录 (十一)

Winter vacation work of software engineering practice

Golang operation redis: write and read hash type data

Application scenarios of Catalan number

JUC forkjoinpool branch merge framework - work theft
随机推荐
Personally design a highly concurrent seckill system
[day15] introduce the features, advantages and disadvantages of promise, and how to implement it internally. Implement promise by hand
2022 East China Normal University postgraduate entrance examination machine test questions - detailed solution
Realize PDF to picture conversion with C #
【类和对象】深入浅出类和对象
[vscode - vehicle plug-in reports an error] cannot find module 'xxx' or its corresponding type declarations Vetur(2307)
10000小時定律不會讓你成為編程大師,但至少是個好的起點
La loi des 10 000 heures ne fait pas de vous un maître de programmation, mais au moins un bon point de départ
Class and object summary
JMeter test result output
Split small interface
Reading notes of "learn to ask questions"
Advanced API (byte stream & buffer stream)
卡特兰数(Catalan)的应用场景
Pits encountered in the use of El checkbox group
centos php7.3安装redis扩展
In depth analysis of reentrantlock fair lock and unfair lock source code implementation
dataworks自定義函數開發環境搭建
instanceof
万卷书 - 价值投资者指南 [The Education of a Value Investor]