当前位置:网站首页>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对象时调用的构造方法。
代码实现案例


更多了解
边栏推荐
- 例题 可达性统计+bitset的使用
- How OpenHarmony Query Device Type
- gradle尚硅谷笔记
- Opencv图像缩放和平移
- 苹果Meta都在冲的Pancake技术,中国VR团队YVR竟抢先交出产品答卷
- STM32入门开发:编写XPT2046电阻触摸屏驱动(模拟SPI)
- SQL Outer Join Intersection, Union, Difference Query
- PCB layout must know: teach you to correctly lay out the circuit board of the op amp
- 拓朴排序例题
- 上位机开发C#语言:模拟STC串口助手接收单片机发送数据
猜你喜欢

一张图看懂 SQL 的各种 join 用法!

linux下oracle常见操作以及日常积累知识点(函数、定时任务)

STM32+ULN2003 drives 28BYJ4 stepper motor (forward and reverse according to the number of turns)

阿里全新推出:微服务突击手册,把所有操作都写出来了PDF

API 网关简述

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

多线程(进阶) - 2.5w字总结

字节一面:TCP 和 UDP 可以使用同一个端口吗?

Create a Dapp, why choose Polkadot?

SQL Outer Join Intersection, Union, Difference Query
随机推荐
导火索:OAuth 2.0四种授权登录方式必读
字节一面:TCP 和 UDP 可以使用同一个端口吗?
[Office] Collection of Microsoft Office download addresses (offline installation and download of Microsoft's official original version)
Chapter 5: Multithreaded Communication—wait and notify
2022技能大赛训练题:交换机snmp配置
Getting started with Polkadot parachain development, this article is enough
E-sports, convenience, efficiency, security, key words for OriginOS functions
DocuWare平台——文档管理的内容服务和工作流自动化的平台详细介绍(下)
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]
RT-Thread记录(一、RT-Thread 版本、RT-Thread Studio开发环境 及 配合CubeMX开发快速上手)
[Android] How to use RecycleView in Kotlin project
Oracle 19.3 restart 环境
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
Still looking for a network backup resources?Hurry up to collect the following network backup resource search artifact it is worth collecting!
第七章,activiti个人任务分配,动态指定和监听器指定任务委派人「建议收藏」
60行从零开始自己动手写FutureTask是什么体验?
Introduction to SD NAND Flash!
如何测试一下现场的备机失败,转发主机的场景?
In-depth understanding of timeout settings for Istio traffic management
SkiaSharp 之 WPF 自绘 投篮小游戏(案例版)