当前位置:网站首页>UDP通信
UDP通信
2022-08-05 10:54:00 【51CTO】
InetAddress类
IP是网络中存在一个数据,那么Java针对这类特殊的数据,会使用对应的类进行描述、封装。
学习Java中的网络编程,对应的类和接口都在java.net包下:
Java中使用InetAddress类描述封装IP对象。只要在程序中我们需要操作ip地址,只能通过InetAddress对象进行完成。
InetAddress类中没有构造方法,只能通过其中的静态的方法获取到InetAddress对象。
UDP通信
DatagramSocket对象介绍
UDP协议是面向无连接的协议,发送数据的一方尽管发送数据,它不关心接收方是否在接收数据。
在Java中使用DatagramSocket对象表示基于UDP协议的发送端或者是接收端。
数据报套接字是包投递服务的发送或接收点。每个在数据报套接字上发送或接收的包都是单独编址和路由的。从一台机器发送到另一台机器的多个包可能选择不同的路由,也可能按不同的顺序到达。
DatagramPacket对象介绍
数据报包用来实现无连接包投递服务。每条报文仅根据该包中包含的信息从一台机器路由到另一台机器。从一台机器发送到另一台机器的多个包可能选择不同的路由,也可能按不同的顺序到达。不对包投递做出保证。
DatagramPacket:它本身负责的对基于UDP协议发送或者接收的数据进行打包或者拆包的。
如何区分DatagramPacket对象到底是打包还是拆包的对象:完全依赖创建DatagramPacket对象时调用的构造方法。
代码实现案例
更多了解
边栏推荐
- 《分布式云最佳实践》分论坛,8 月 11 日深圳见
- nyoj86 找球号(一) set容器和二分 两种解法
- RT-Thread记录(一、RT-Thread 版本、RT-Thread Studio开发环境 及 配合CubeMX开发快速上手)
- 第七章,activiti个人任务分配,动态指定和监听器指定任务委派人「建议收藏」
- How to choose coins and determine the corresponding strategy research
- 深入理解 Istio 流量管理的超时时间设置
- poj2935 Basic Wall Maze (2016xynu暑期集训检测 -----D题)
- 数分面试(一)----与业务相关
- 登录功能和退出功能(瑞吉外卖)
- 化繁为简!阿里新产亿级流量系统设计核心原理高级笔记(终极版)
猜你喜欢
双因子与多因子身份验证有什么区别?
脱光衣服待着就能减肥,当真有这好事?
The century-old Nordic luxury home appliance brand ASKO smart wine cabinet in the three-temperature area presents the Chinese Valentine’s Day, and tastes the love of the delicacy
化繁为简!阿里新产亿级流量系统设计核心原理高级笔记(终极版)
JS introduction to reverse the recycling business network of learning, simple encryption mobile phone number
How to choose coins and determine the corresponding strategy research
阿里全新推出:微服务突击手册,把所有操作都写出来了PDF
The host computer develops C# language: simulates the STC serial port assistant to receive the data sent by the microcontroller
这份阿里强推的并发编程知识点笔记,将是你拿大厂offer的突破口
Common operations of oracle under linux and daily accumulation of knowledge points (functions, timed tasks)
随机推荐
【C语言指针】用指针提升数组的运算效率
FPGA: Use of the development environment Vivado
什么是 DevOps?看这一篇就够了!
abc262-D(dp)
Getting started with Polkadot parachain development, this article is enough
Header file search rules when compiling with GCC
【AGC】增长服务1-远程配置示例
STM32入门开发:编写XPT2046电阻触摸屏驱动(模拟SPI)
poj2287 Tian Ji -- The Horse Racing(2016xynu暑期集训检测 -----C题)
Oracle 19.3 restart 环境
FPGA:开发环境Vivado的使用
A small test of basic grammar, Go lang1.18 introductory refining tutorial, from Bai Ding to Hongru, basic grammar of go lang and the use of variables EP02
MMDetection in action: MMDetection training and testing
How OpenHarmony Query Device Type
The query that the user's test score is greater than the average score of a single subject
Chapter 4: activiti RuntimeService settings get and get process variables, and the difference from taskService, set process variables when starting and completing tasks [easy to understand]
FPGA: Basic Getting Started LED Lights Blinking
The JVM collection that Alibaba's top architects have summarized for many years, where can't I check it!
Login function and logout function (St. Regis Takeaway)
Offensive World-PWN-new_easypwn