public abstract class NetworkBase extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
protected Socket |
CoreSocket
对客户端而言是的通讯用的套接字,对服务器来说是用于侦听的套接字
A communication socket for the client, or a listening socket for the server |
protected int |
fileCacheSize
文件传输的时候的缓存大小,直接影响传输的速度,值越大,传输速度越快,越占内存,默认为100K大小
The size of the cache during file transfer directly affects the speed of the transfer. |
ILogNet |
LogNet
组件的日志工具,支持日志记录,只要实例化后,当前网络的基本信息,就以
HslMessageDegree.Debug 等级进行输出The component's logging tool supports logging. |
UUID |
Token
网络类的身份令牌,在hsl协议的模式下会有效,在和设备进行通信的时候是无效的
Network-type identity tokens will be valid in the hsl protocol mode and will not be valid when communicating with the device |
| 构造器和说明 |
|---|
NetworkBase()
实例化一个NetworkBase对象,令牌的默认值为空,都是0x00
Instantiate a NetworkBase object, the default value of the token is empty, both are 0x00 |
| 限定符和类型 | 方法和说明 |
|---|---|
protected boolean |
CheckRemoteToken(byte[] headBytes)
检查当前的头子节信息的令牌是否是正确的,仅用于某些特殊的协议实现
Check whether the token of the current header subsection information is correct, only for some special protocol implementations |
protected void |
CloseSocket(Socket socket)
安全的关闭一个套接字
|
protected OperateResultExOne<Socket> |
CreateSocketAndConnect(SocketAddress endPoint,
int timeOut)
创建一个新的socket对象并连接到远程的地址,需要指定ip地址以及端口号信息,还有超时时间,单位是毫秒
To create a new socket object and connect to a remote address, you need to specify the IP address and port number information, and the timeout period in milliseconds |
protected OperateResultExOne<Socket> |
CreateSocketAndConnect(String ipAddress,
int port)
创建一个新的socket对象并连接到远程的地址,默认超时时间为10秒钟,需要指定ip地址以及端口号信息
Create a new socket object and connect to the remote address. |
protected OperateResultExOne<Socket> |
CreateSocketAndConnect(String ipAddress,
int port,
int timeOut)
创建一个新的socket对象并连接到远程的地址,需要指定ip地址以及端口号信息,还有超时时间,单位是毫秒
To create a new socket object and connect to a remote address, you need to specify the IP address and port number information, and the timeout period in milliseconds |
protected OperateResultExOne<Integer> |
ReadStream(InputStream stream,
byte[] buffer)
读取流中的数据到缓存区,读取的长度需要按照实际的情况来判断
Read the data in the stream to the buffer area. |
protected OperateResultExOne<byte[]> |
Receive(Socket socket,
int length)
接收固定长度的字节数组,允许指定超时时间,默认为60秒,当length大于0时,接收固定长度的数据内容,当length小于0时,接收不大于1024长度的随机数据信息
Receiving a fixed-length byte array, allowing a specified timeout time. |
protected OperateResultExOne<byte[]> |
Receive(Socket socket,
int length,
int timeout)
接收固定长度的字节数组,需要指定超时时间,当length大于0时,接收固定长度的数据内容,当length小于0时,接收不大于1024长度的随机数据信息
To receive a fixed-length byte array, you need to specify the timeout period. |
protected OperateResultExOne<byte[]> |
Receive(Socket socket,
int length,
int timeout,
ActionOperateExTwo<Long,Long> reportProgress)
接收固定长度的字节数组,需要指定超时时间,当length大于0时,接收固定长度的数据内容,当length小于0时,接收不大于1024长度的随机数据信息
To receive a fixed-length byte array, you need to specify the timeout period. |
protected OperateResultExTwo<byte[],byte[]> |
ReceiveAndCheckBytes(Socket socket,
int timeout)
[自校验] 接收一条完整的同步数据,包含头子节和内容字节,基础的数据,如果结果异常,则结束通讯
[Self-checking] Receive a complete synchronization data, including header subsection and content bytes, basic data, if the result is abnormal, the communication ends |
protected OperateResultExOne<byte[]> |
ReceiveByMessage(Socket socket,
int timeOut,
INetMessage netMessage)
接收一条完整的
INetMessage 数据内容,需要指定超时时间,单位为毫秒。 |
protected OperateResultExOne<byte[]> |
ReceiveByMessage(Socket socket,
int timeOut,
INetMessage netMessage,
ActionOperateExTwo<Long,Long> reportProgress)
接收一条完整的
INetMessage 数据内容,需要指定超时时间,单位为毫秒。 |
protected OperateResultExTwo<Integer,byte[]> |
ReceiveBytesContentFromSocket(Socket socket)
[自校验] 从网络中接收一串字节数据,如果结果异常,则结束通讯
[Self-checking] Receive a string of byte data from the network. |
protected OperateResultExTwo<Integer,byte[]> |
ReceiveBytesContentFromSocket(Socket socket,
int timeout)
[自校验] 从网络中接收一串字节数据,如果结果异常,则结束通讯
[Self-checking] Receive a string of byte data from the network. |
protected OperateResultExOne<byte[]> |
ReceiveCommandLineFromSocket(Socket socket,
byte endCode)
接收一行命令数据,需要自己指定这个结束符,指定超时时间
To receive a line of command data, you need to specify the terminator yourself. and also the timeout value |
protected OperateResultExOne<byte[]> |
ReceiveCommandLineFromSocket(Socket socket,
byte endCode1,
byte endCode2)
接收一行命令数据,需要自己指定这个结束符,默认超时时间60秒,单位是毫秒
To receive a line of command data, you need to specify the terminator yourself. |
protected OperateResultExOne<byte[]> |
ReceiveCommandLineFromSocket(Socket socket,
byte endCode1,
byte endCode2,
int timeout)
接收一行命令数据,需要自己指定这个结束符,指定超时时间,单位是毫秒
To receive a line of command data, you need to specify the terminator yourself. and also the timeout value |
protected OperateResultExOne<byte[]> |
ReceiveCommandLineFromSocket(Socket socket,
byte endCode,
int timeout)
接收一行命令数据,需要自己指定这个结束符,指定超时时间
To receive a line of command data, you need to specify the terminator yourself. and also the timeout value |
protected OperateResultExTwo<WebSocketMessage,Boolean> |
ReceiveFrameWebSocketPayload(Socket socket)
从socket接收一条
WebSocketMessage 片段数据,返回 WebSocketMessage 的数据信息和是否最后一条数据内容Receive a piece of WebSocketMessage fragment data from the socket, return the data information of WebSocketMessage and whether the last data content |
protected OperateResultExThree<Integer,Integer,byte[]> |
ReceiveHslMessage(Socket socket)
接收一条hsl协议的数据信息,自动解析,解压,解码操作,获取最后的实际的数据,接收结果依次为暗号,用户码,负载数据
Receive a piece of hsl protocol data information, automatically parse, decompress, and decode operations to obtain the last actual data. |
protected OperateResultExTwo<Byte,byte[]> |
ReceiveMqttMessage(Socket socket,
int timeOut,
ActionOperateExTwo<Long,Long> reportProgress)
接收一条完成的MQTT协议的报文信息,包含控制码和负载数据
Receive a message of a completed MQTT protocol, including control code and payload data |
protected OperateResultExOne<byte[]> |
ReceiveRedisCommand(Socket socket)
从网络接收一条完整的redis报文的消息
Receive a complete redis message from the network |
protected OperateResultExOne<byte[]> |
ReceiveRedisCommandString(Socket socket,
int length)
接收一行基于redis协议的字符串的信息,需要指定固定的长度
Receive a line of information based on the redis protocol string, you need to specify a fixed length |
protected OperateResultExTwo<Integer,String[]> |
ReceiveStringArrayContentFromSocket(Socket socket)
[自校验] 从网络中接收一个字符串数组,如果结果异常,则结束通讯
[Self-check] Receive an array of strings from the network. |
protected OperateResultExTwo<Integer,String[]> |
ReceiveStringArrayContentFromSocket(Socket socket,
int timeout)
[自校验] 从网络中接收一个字符串数组,如果结果异常,则结束通讯
[Self-check] Receive an array of strings from the network. |
protected OperateResultExTwo<Integer,String> |
ReceiveStringContentFromSocket(Socket socket)
[自校验] 从网络中接收一个字符串数据,如果结果异常,则结束通讯
[Self-checking] Receive a string of data from the network. |
protected OperateResultExTwo<Integer,String> |
ReceiveStringContentFromSocket(Socket socket,
int timeout)
[自校验] 从网络中接收一个字符串数据,如果结果异常,则结束通讯
[Self-checking] Receive a string of data from the network. |
protected OperateResultExOne<WebSocketMessage> |
ReceiveWebSocketPayload(Socket socket)
从socket接收一条完整的 websocket 数据,返回
WebSocketMessage 的数据信息Receive a complete websocket data from the socket, return the data information of the WebSocketMessage |
protected OperateResult |
Send(Socket socket,
byte[] data)
发送消息给套接字,直到完成的时候返回,经过测试,本方法是线程安全的。
|
protected OperateResult |
Send(Socket socket,
byte[] data,
int offset,
int size)
发送消息给套接字,直到完成的时候返回,经过测试,本方法是线程安全的。
|
protected OperateResult |
SendAccountAndCheckReceive(Socket socket,
int customer,
String name,
String pwd)
[自校验] 直接发送字符串数组并确认对方接收完成数据,如果结果异常,则结束通讯
[Self-check] Send string array directly and confirm that the other party has received the completed data. |
protected OperateResult |
SendBaseAndCheckReceive(Socket socket,
int headCode,
int customer,
byte[] send)
[自校验] 发送字节数据并确认对方接收完成数据,如果结果异常,则结束通讯
[Self-check] Send the byte data and confirm that the other party has received the completed data. |
protected OperateResult |
SendBytesAndCheckReceive(Socket socket,
int customer,
byte[] send)
[自校验] 发送字节数据并确认对方接收完成数据,如果结果异常,则结束通讯
[Self-check] Send the byte data and confirm that the other party has received the completed data. |
protected OperateResult |
SendStreamToSocket(Socket socket,
InputStream stream,
long receive,
ActionOperateExTwo<Long,Long> report,
boolean reportByPercent)
发送一个流的所有数据到指定的网络套接字,需要指定发送的数据长度,支持按照百分比的进度报告
Send all the data of a stream to the specified network socket. |
protected OperateResult |
SendStringAndCheckReceive(Socket socket,
int customer,
String send)
[自校验] 直接发送字符串数据并确认对方接收完成数据,如果结果异常,则结束通讯
[Self-checking] Send string data directly and confirm that the other party has received the completed data. |
protected OperateResult |
SendStringAndCheckReceive(Socket socket,
int customer,
String[] sends)
[自校验] 直接发送字符串数组并确认对方接收完成数据,如果结果异常,则结束通讯
[Self-check] Send string array directly and confirm that the other party has received the completed data. |
protected void |
ThreadPoolCheckTimeOut(HslTimeOut timeout)
检查网络套接字是否操作超时,传入的参数需要是
HslTimeOut 类型,封装socket操作。 |
String |
toString()
返回当前对象表示的字符串
Returns the string represented by the current object |
protected OperateResult |
WriteStream(OutputStream stream,
byte[] buffer)
将缓冲区的数据写入到流里面去
Write the buffer data to the stream |
protected OperateResult |
WriteStreamFromSocket(Socket socket,
OutputStream stream,
long totalLength,
ActionOperateExTwo<Long,Long> report,
boolean reportByPercent)
从套接字中接收所有的数据然后写入到指定的流当中去,需要指定数据的长度,支持按照百分比进行进度报告
Receives all data from the socket and writes it to the specified stream. |
public ILogNet LogNet
HslMessageDegree.Debug 等级进行输出HslMessageDegree.Debug "public UUID Token
protected Socket CoreSocket
protected int fileCacheSize
public NetworkBase()
protected void ThreadPoolCheckTimeOut(HslTimeOut timeout)
HslTimeOut 类型,封装socket操作。HslTimeOut to encapsulate the socket operation.timeout - HslTimeOut的对象protected OperateResultExOne<byte[]> Receive(Socket socket, int length, int timeout, ActionOperateExTwo<Long,Long> reportProgress)
socket - 网络通讯的套接字,Network communication socketlength - 准备接收的数据长度,当length大于0时,接收固定长度的数据内容,当length小于0时,接收不大于1024长度的随机数据信息timeout - 单位:毫秒,超时时间,默认为60秒,如果设置小于0,则不检查超时时间reportProgress - 当前接收数据的进度报告,有些协议支持传输非常大的数据内容,可以给与进度提示的功能protected OperateResultExOne<byte[]> Receive(Socket socket, int length, int timeout)
socket - 网络通讯的套接字,Network communication socketlength - 准备接收的数据长度,当length大于0时,接收固定长度的数据内容,当length小于0时,接收不大于1024长度的随机数据信息timeout - 单位:毫秒,超时时间,默认为60秒,如果设置小于0,则不检查超时时间protected OperateResultExOne<byte[]> Receive(Socket socket, int length)
socket - 网络通讯的套接字,Network communication socketlength - 准备接收的数据长度,当length大于0时,接收固定长度的数据内容,当length小于0时,接收不大于1024长度的随机数据信息protected OperateResultExOne<byte[]> ReceiveCommandLineFromSocket(Socket socket, byte endCode, int timeout)
socket - 网络套接字endCode - 结束符信息timeout - 超时时间,单位毫秒protected OperateResultExOne<byte[]> ReceiveCommandLineFromSocket(Socket socket, byte endCode)
socket - 网络套接字endCode - 结束符信息protected OperateResultExOne<byte[]> ReceiveCommandLineFromSocket(Socket socket, byte endCode1, byte endCode2, int timeout)
socket - 网络套接字endCode1 - 结束符1信息endCode2 - 结束符2信息timeout - 超时时间,默认无穷大,单位毫秒protected OperateResultExOne<byte[]> ReceiveCommandLineFromSocket(Socket socket, byte endCode1, byte endCode2)
socket - 网络套接字endCode1 - 结束符1信息endCode2 - 结束符2信息protected OperateResultExOne<byte[]> ReceiveByMessage(Socket socket, int timeOut, INetMessage netMessage, ActionOperateExTwo<Long,Long> reportProgress)
INetMessage 数据内容,需要指定超时时间,单位为毫秒。 INetMessage data content, Need to specify a timeout period in millisecondssocket - 网络的套接字timeOut - 超时时间,单位:毫秒netMessage - 消息的格式定义reportProgress - 接收消息的时候的进度报告protected OperateResultExOne<byte[]> ReceiveByMessage(Socket socket, int timeOut, INetMessage netMessage)
INetMessage 数据内容,需要指定超时时间,单位为毫秒。 INetMessage data content, Need to specify a timeout period in millisecondssocket - 网络的套接字timeOut - 超时时间,单位:毫秒netMessage - 消息的格式定义protected OperateResult Send(Socket socket, byte[] data)
socket - 网络套接字data - 数据protected OperateResult Send(Socket socket, byte[] data, int offset, int size)
socket - 网络套接字data - 字节数据offset - 偏移的位置信息size - 发送的数据总数protected OperateResultExOne<Socket> CreateSocketAndConnect(SocketAddress endPoint, int timeOut)
endPoint - 目标节点timeOut - 超时时间protected OperateResultExOne<Socket> CreateSocketAndConnect(String ipAddress, int port, int timeOut)
ipAddress - ip地址port - 端口号timeOut - 超时时间protected OperateResultExOne<Socket> CreateSocketAndConnect(String ipAddress, int port)
ipAddress - ip地址port - 端口号protected OperateResultExOne<Integer> ReadStream(InputStream stream, byte[] buffer)
stream - 流数据buffer - 缓冲数据protected OperateResult WriteStream(OutputStream stream, byte[] buffer)
stream - 字节流buffer - 缓存数据protected boolean CheckRemoteToken(byte[] headBytes)
headBytes - 头子节数据protected OperateResult SendBaseAndCheckReceive(Socket socket, int headCode, int customer, byte[] send)
socket - 网络套接字headCode - 头指令customer - 用户指令send - 发送的数据protected OperateResult SendBytesAndCheckReceive(Socket socket, int customer, byte[] send)
socket - 网络套接字customer - 用户指令send - 发送的数据protected OperateResult SendStringAndCheckReceive(Socket socket, int customer, String send)
socket - 网络套接字customer - 用户指令send - 发送的数据protected OperateResult SendStringAndCheckReceive(Socket socket, int customer, String[] sends)
socket - 网络套接字customer - 用户指令sends - 发送的字符串数组protected OperateResult SendAccountAndCheckReceive(Socket socket, int customer, String name, String pwd)
socket - 网络套接字customer - 用户指令name - 用户名pwd - 密码protected OperateResultExTwo<byte[],byte[]> ReceiveAndCheckBytes(Socket socket, int timeout)
socket - 套接字timeout - 超时时间设置,如果为负数,则不检查超时protected OperateResultExTwo<Integer,String> ReceiveStringContentFromSocket(Socket socket)
socket - 套接字protected OperateResultExTwo<Integer,String> ReceiveStringContentFromSocket(Socket socket, int timeout)
socket - 套接字timeout - 超时时间protected OperateResultExTwo<Integer,String[]> ReceiveStringArrayContentFromSocket(Socket socket)
socket - 套接字protected OperateResultExTwo<Integer,String[]> ReceiveStringArrayContentFromSocket(Socket socket, int timeout)
socket - 套接字protected OperateResultExTwo<Integer,byte[]> ReceiveBytesContentFromSocket(Socket socket)
socket - 套接字的网络protected OperateResultExTwo<Integer,byte[]> ReceiveBytesContentFromSocket(Socket socket, int timeout)
socket - 套接字的网络timeout - 超时时间protected void CloseSocket(Socket socket)
socket - 网络套接字protected OperateResult SendStreamToSocket(Socket socket, InputStream stream, long receive, ActionOperateExTwo<Long,Long> report, boolean reportByPercent)
socket - 套接字stream - 内存流receive - 发送的数据长度report - 进度报告的委托reportByPercent - 进度报告是否按照百分比报告protected OperateResult WriteStreamFromSocket(Socket socket, OutputStream stream, long totalLength, ActionOperateExTwo<Long,Long> report, boolean reportByPercent)
socket - 套接字stream - 数据流totalLength - 所有数据的长度report - 进度报告reportByPercent - 进度报告是否按照百分比protected OperateResultExOne<WebSocketMessage> ReceiveWebSocketPayload(Socket socket)
WebSocketMessage 的数据信息WebSocketMessagesocket - 网络套接字protected OperateResultExTwo<WebSocketMessage,Boolean> ReceiveFrameWebSocketPayload(Socket socket)
WebSocketMessage 片段数据,返回 WebSocketMessage 的数据信息和是否最后一条数据内容WebSocketMessage fragment data from the socket, return the data information of WebSocketMessage and whether the last data contentsocket - 网络套接字protected OperateResultExTwo<Byte,byte[]> ReceiveMqttMessage(Socket socket, int timeOut, ActionOperateExTwo<Long,Long> reportProgress)
socket - 网络套接字timeOut - 超时实际NreportProgress - 进度报告,第一个参数是已完成的字节数量,第二个参数是总字节数量。protected OperateResultExOne<byte[]> ReceiveRedisCommandString(Socket socket, int length)
socket - 网络套接字length - 字符串的长度protected OperateResultExOne<byte[]> ReceiveRedisCommand(Socket socket)
socket - 网络套接字protected OperateResultExThree<Integer,Integer,byte[]> ReceiveHslMessage(Socket socket)
socket - 网络套接字Copyright © 2022. All rights reserved.