public interface ComProtocol
Modifier and Type | Interface and Description |
---|---|
static class |
ComProtocol.Configuration
Protocol configuration class
|
static interface |
ComProtocol.IOnEvent<T> |
static interface |
ComProtocol.OnConnectionStatusChangeListener
Event when the protocol connection status change
|
static interface |
ComProtocol.OnErrorListener
Event when an error occur
|
Modifier and Type | Method and Description |
---|---|
void |
addOnConnectionStatusChangeListener(ComProtocol.OnConnectionStatusChangeListener listener)
Set the message listener
|
void |
addOnErrorListener(ComProtocol.OnErrorListener listener)
Set the message listener
|
void |
addOnMessageListener(ComProtocol.IOnEvent<byte[]> listener)
Set the message listener
|
void |
connect()
Connect to the protocol
|
void |
disconnect()
Disconnect from the protocol
|
ComProtocol.Configuration |
getConfiguration() |
ConnectionState |
getConnectionStatus()
Get the current connection status
|
java.lang.Throwable |
getLastError() |
HostProtocol |
getType()
Get com protocol type
|
boolean |
isConnected() |
void |
notifyNewMessage(byte[] message) |
byte[] |
read()
Read input data
|
boolean |
removeOnConnectionStatusChangeListener(ComProtocol.OnConnectionStatusChangeListener listener) |
boolean |
removeOnErrorListener(ComProtocol.OnErrorListener listener) |
byte[] |
send(byte[] message)
Write request and wait for response
|
void |
sendAsync(byte[] message,
ComProtocol.IOnEvent<byte[]> event)
Send data asynchronously
|
void |
write(byte[] data)
Write without waiting for a response
|
ConnectionState getConnectionStatus()
HostProtocol getType()
@Nullable java.lang.Throwable getLastError()
boolean isConnected()
void connect() throws java.lang.Exception
java.lang.Exception
- when connection failsvoid disconnect() throws java.lang.Exception
java.lang.Exception
- when disconnection failsvoid write(byte[] data) throws java.lang.Exception
data
- data to sendjava.lang.Exception
- when send failsbyte[] read() throws java.lang.Exception
java.lang.Exception
- when read failsbyte[] send(byte[] message) throws java.lang.Exception
message
- the data to sendjava.lang.Exception
- when send failsvoid sendAsync(byte[] message, ComProtocol.IOnEvent<byte[]> event)
message
- the data to sendevent
- callback eventvoid notifyNewMessage(byte[] message)
message
- the input message receivedvoid addOnMessageListener(ComProtocol.IOnEvent<byte[]> listener)
listener
- the listnervoid addOnConnectionStatusChangeListener(ComProtocol.OnConnectionStatusChangeListener listener)
listener
- the listenerboolean removeOnConnectionStatusChangeListener(ComProtocol.OnConnectionStatusChangeListener listener)
listener
- the listenerComProtocol.Configuration getConfiguration()
void addOnErrorListener(ComProtocol.OnErrorListener listener)
listener
- the listenerboolean removeOnErrorListener(ComProtocol.OnErrorListener listener)
listener
- the listener