public class NetworkDoubleBase extends NetworkBase
| 限定符和类型 | 字段和说明 |
|---|---|
AlienSession |
AlienSession
当前的异形连接对象,如果设置了异性连接的话
|
protected boolean |
isPersistentConn |
protected boolean |
IsSocketError |
protected boolean |
isUseAccountCertificate
是否使用账号登录,这个账户登录的功能是
|
protected boolean |
LogMsgFormatBinary
设置日志记录报文是否二进制,如果为False,那就使用ASCII码
Set whether the log message is binary, if it is False, then use ASCII code |
protected SimpleHybirdLock |
simpleHybirdLock |
CoreSocket, fileCacheSize, LogNet, Token| 构造器和说明 |
|---|
NetworkDoubleBase()
默认的无参构造函数
|
| 限定符和类型 | 方法和说明 |
|---|---|
protected OperateResult |
AccountCertificate(Socket socket)
认证账号,根据已经设置的用户名和密码,进行发送服务器进行账号认证。
|
OperateResult |
ConnectClose()
手动断开与远程服务器的连接,如果当前是长连接模式,那么就会切换到短连接模式
Manually disconnect from the remote server, if it is currently in long connection mode, it will switch to short connection mode |
OperateResult |
ConnectServer()
尝试连接远程的服务器,如果连接成功,就切换短连接模式到长连接模式,后面的每次请求都共享一个通道,使得通讯速度更快速
Try to connect to a remote server. |
OperateResult |
ConnectServer(AlienSession session)
使用指定的套接字创建异形客户端,在异形客户端的模式下,网络通道需要被动创建。
|
protected void |
ExtraAfterReadFromCoreServer(OperateResult read)
和服务器交互完成的时候调用的方法,可以根据读写结果进行一些额外的操作,具体的操作需要根据实际的需求来重写实现
The method called when the interaction with the server is completed can perform some additional operations based on the read and write results. |
protected OperateResult |
ExtraOnDisconnect(Socket socket)
根据实际的协议选择是否重写本方法,有些协议在断开连接之前,需要发送一些报文来关闭当前的网络通道
Select whether to rewrite this method according to the actual protocol. |
protected OperateResultExOne<Socket> |
GetAvailableSocket()
获取本次操作的可用的网络通道,如果是短连接,就重新生成一个新的网络通道,如果是长连接,就复用当前的网络通道。
|
IByteTransform |
getByteTransform()
获取当前的数据变换机制,当你需要从字节数据转换类型数据的时候需要。
|
String |
getConnectionId()
当前连接的唯一ID号,默认为长度20的guid码加随机数组成,也可以自己指定
|
int |
getConnectTimeOut()
获取连接的超时时间,单位是毫秒
Gets the timeout for the connection, in milliseconds |
String |
getIpAddress()
获取远程服务器的IP地址,如果是本机测试,那么需要设置为127.0.0.1
Get the IP address of the remote server. |
protected INetMessage |
GetNewNetMessage()
获取一个新的消息对象的方法,需要在继承类里面进行重写
The method to get a new message object needs to be overridden in the inheritance class |
int |
getPort()
获取服务器的端口号,具体的值需要取决于对方的配置
Gets the port number of the server. |
int |
getReceiveTimeOut()
获取接收服务器反馈的时间,如果为负数,则不接收反馈
Gets the time to receive server feedback, and if it is a negative number, does not receive feedback |
int |
getSleepTime()
获取在正式接收对方返回数据前的时候,需要休息的时间。
|
protected OperateResult |
InitializationOnConnect(Socket socket)
根据实际的协议选择是否重写本方法,有些协议在创建连接之后,需要进行一些初始化的信号握手,才能最终建立网络通道。
|
boolean |
IpAddressPing()
对当前设备的IP地址进行PING的操作,返回PING的结果,正常来说,返回 True
|
protected byte[] |
PackCommandWithHeader(byte[] command)
对当前的命令进行打包处理,通常是携带命令头内容,标记当前的命令的长度信息,需要进行重写,否则默认不打包
|
OperateResultExOne<byte[]> |
ReadFromCoreServer(byte[] send)
将数据发送到当前的网络通道中,并从网络通道中接收一个
INetMessage 指定的完整的报文,网络通道将根据 GetAvailableSocket() 方法自动获取,本方法是线程安全的。 |
OperateResultExOne<byte[]> |
ReadFromCoreServer(byte[] send,
boolean hasResponseData,
boolean usePackAndUnpack)
将数据发送到当前的网络通道中,并从网络通道中接收一个
INetMessage 指定的完整的报文,网络通道将根据 GetAvailableSocket() 方法自动获取,本方法是线程安全的。 |
OperateResultExOne<byte[]> |
ReadFromCoreServer(Socket socket,
byte[] send,
boolean hasResponseData,
boolean usePackAndUnpack)
将数据报文发送指定的网络通道上,根据当前指定的
INetMessage 类型,返回一条完整的数据指令Sends a data message to the specified network channel, and returns a complete data command according to the currently specified |
void |
setByteTransform(IByteTransform transform)
设置当前的数据变换机制,当你需要从字节数据转换类型数据的时候需要。
|
void |
setConnectionId(String connectionId)
当前连接的唯一ID号,默认为长度20的guid码加随机数组成,方便列表管理,也可以自己指定
The unique ID number of the current connection. |
void |
setConnectTimeOut(int connectTimeOut)
设置连接的超时时间,单位是毫秒
Sets the timeout for the connection, in milliseconds |
void |
setIpAddress(String ipAddress)
设置远程服务器的IP地址,如果是本机测试,那么需要设置为127.0.0.1
Set the IP address of the remote server. |
void |
SetLoginAccount(String userName,
String password)
设置当前的登录的账户名和密码信息,并启用账户验证的功能,账户名为空时设置不生效
Set the current login account name and password information, and enable the account verification function. |
void |
SetPersistentConnection()
在读取数据之前可以调用本方法将客户端设置为长连接模式,相当于跳过了ConnectServer的结果验证,对异形客户端无效,当第一次进行通信时再进行创建连接请求。
|
void |
setPort(int port)
设置服务器的端口号,具体的值需要取决于对方的配置
Sets the port number of the server. |
void |
setReceiveTimeOut(int receiveTimeOut)
设置接收服务器反馈的时间,如果为负数,则不接收反馈
Sets the time to receive server feedback, and if it is a negative number, does not receive feedback |
void |
setSleepTime(int sleepTime)
设置接收对方返回数据前的时候,需要休息的时间,当设置为0的时候,不需要休息。
|
String |
toString()
返回当前对象表示的字符串
Returns the string represented by the current object |
protected OperateResultExOne<byte[]> |
UnpackResponseContent(byte[] send,
byte[] response)
根据对方返回的报文命令,对命令进行基本的拆包,例如各种Modbus协议拆包为统一的核心报文,还支持对报文的验证
|
CheckRemoteToken, CloseSocket, CreateSocketAndConnect, CreateSocketAndConnect, CreateSocketAndConnect, ReadStream, Receive, Receive, Receive, ReceiveAndCheckBytes, ReceiveByMessage, ReceiveByMessage, ReceiveBytesContentFromSocket, ReceiveBytesContentFromSocket, ReceiveCommandLineFromSocket, ReceiveCommandLineFromSocket, ReceiveCommandLineFromSocket, ReceiveCommandLineFromSocket, ReceiveFrameWebSocketPayload, ReceiveHslMessage, ReceiveMqttMessage, ReceiveRedisCommand, ReceiveRedisCommandString, ReceiveStringArrayContentFromSocket, ReceiveStringArrayContentFromSocket, ReceiveStringContentFromSocket, ReceiveStringContentFromSocket, ReceiveWebSocketPayload, Send, Send, SendAccountAndCheckReceive, SendBaseAndCheckReceive, SendBytesAndCheckReceive, SendStreamToSocket, SendStringAndCheckReceive, SendStringAndCheckReceive, ThreadPoolCheckTimeOut, WriteStream, WriteStreamFromSocketprotected boolean isPersistentConn
protected SimpleHybirdLock simpleHybirdLock
protected boolean IsSocketError
protected boolean LogMsgFormatBinary
public AlienSession AlienSession
protected boolean isUseAccountCertificate
protected INetMessage GetNewNetMessage()
public IByteTransform getByteTransform()
public void setByteTransform(IByteTransform transform)
transform - 数据变换public int getConnectTimeOut()
public void setConnectTimeOut(int connectTimeOut)
connectTimeOut - 超时时间,单位是秒public int getReceiveTimeOut()
public void setReceiveTimeOut(int receiveTimeOut)
receiveTimeOut - 数值public String getIpAddress()
public void setIpAddress(String ipAddress)
ipAddress - IP地址public int getPort()
public void setPort(int port)
port - 端口号public String getConnectionId()
public void setConnectionId(String connectionId)
connectionId - 连接的id信息public int getSleepTime()
public void setSleepTime(int sleepTime)
sleepTime - 睡眠时间public void SetPersistentConnection()
public boolean IpAddressPing()
throws IOException
IOException - 异常信息public OperateResult ConnectServer()
public OperateResult ConnectServer(AlienSession session)
session - 会话public OperateResult ConnectClose()
protected OperateResult InitializationOnConnect(Socket socket)
socket - 网络套接字protected OperateResult ExtraOnDisconnect(Socket socket)
socket - 网络套接字protected void ExtraAfterReadFromCoreServer(OperateResult read)
read - 读取结果public void SetLoginAccount(String userName, String password)
userName - 账户名password - 密码protected OperateResult AccountCertificate(Socket socket)
socket - 套接字protected byte[] PackCommandWithHeader(byte[] command)
command - 发送的数据命令内容protected OperateResultExOne<byte[]> UnpackResponseContent(byte[] send, byte[] response)
send - 发送的原始报文数据response - 设备方反馈的原始报文内容protected OperateResultExOne<Socket> GetAvailableSocket()
public OperateResultExOne<byte[]> ReadFromCoreServer(Socket socket, byte[] send, boolean hasResponseData, boolean usePackAndUnpack)
INetMessage 类型,返回一条完整的数据指令socket - 指定的套接字send - 发送的完整的报文信息hasResponseData - 是否有等待的数据返回usePackAndUnpack - 是否需要对命令重新打包public OperateResultExOne<byte[]> ReadFromCoreServer(byte[] send, boolean hasResponseData, boolean usePackAndUnpack)
INetMessage 指定的完整的报文,网络通道将根据 GetAvailableSocket() 方法自动获取,本方法是线程安全的。INetMessage from the network channel.
The network channel will be automatically obtained according to the GetAvailableSocket() method This method is thread-safe.send - 发送的完整的报文信息hasResponseData - 是否有等待的数据返回usePackAndUnpack - 是否需要对命令重新打包public OperateResultExOne<byte[]> ReadFromCoreServer(byte[] send)
INetMessage 指定的完整的报文,网络通道将根据 GetAvailableSocket() 方法自动获取,本方法是线程安全的。INetMessage from the network channel.
The network channel will be automatically obtained according to the GetAvailableSocket() method This method is thread-safe.send - 发送的完整的报文信息public String toString()
NetworkBasetoString 在类中 NetworkBaseCopyright © 2022. All rights reserved.