readInt函数的使用
来源:互联网 发布:c语言开发实战宝典 编辑:程序博客网 时间:2024/05/23 18:10
今天看人家java网络编程源码的时候,看到readInt函数。由于自己对java不是很熟悉,虽然从函数字面意思大概知道函数的用法,还是进一步查阅了java api文档。下面内容是从java api文档中摘抄的:
readInt
public final int readInt() throws IOException
- See the general contract of the
readInt
method ofDataInput
.Bytes for this operation are read from the contained input stream.
- Specified by:
readInt
in interfaceDataInput
- Returns:
- the next four bytes of this input stream, interpreted as an
int
. - Throws:
EOFException
- if this input stream reaches the end before reading four bytes.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.- See Also:
FilterInputStream.in
注意标红的部分,该函数的意思就是从输入流中读取四个字节。在网络编程中,经常需要构造自己的包结构,最简单的就是用最开始的4bit存储后续data部分的长度。这样在java网络编程中,首先就可以利用readInt函数来读取data部分的长度,然后在利用recv函数循环接受数据内容时,利用该长度值作为判断条件,从而正确接收网络数据。
0 0
- readInt函数的使用
- DataInputStream 的readInt 算法
- Socket 应用中DataInputStream 的readInt()方法
- PHP 实现文件的writeInt writeUTF readInt readUTF
- Java采用readInt()方法直接读取特定的ZIP压缩文件出现了奇怪的问题
- 改变Nim 标准库中streams 模块里的readInt 系列过程
- 改变Nim 标准库中streams 模块里的readInt 系列过程
- public final int readInt()
- Readint and Writint
- Android MediaRecorder H264 编码实时视频流不能播放(readInt()值太大)以及如何将流实时上传到服务器的方法
- 使用excel的函数
- format函数的使用
- format函数的使用
- SetTimer函数的使用
- showModalDialog函数的使用
- 函数对象的使用
- DECODE函数的使用
- IIF函数的使用
- Android Application生命周期学习
- Java线程集合类ConcurrentHashMap&CopyOnWriteArrayList 深入
- Androidmarket开发者账号申请
- Tomcat设置为系统服务项,随开机自动启动
- Sicily 1817
- readInt函数的使用
- 设计模式(18)——备忘录模式
- 关于C++中的临时对象问题
- calayer基础学习
- 字符串替换 STL
- 设计模式(19)——状态模式
- c语言基础之指针与一维数组
- Google Play应用商店开发者账号注册教程
- Python Decorator(装饰器)