Capacitor Socket Connection Plugin
npm install @spryrocks/capacitor-socket-connection-plugin@5.1.9
see main-capacitor2 branch for capacitor 2
const socket = new Socket();
socket.onData = function(data) {
// handle received data
};
Name | Type |
---|---|
data | Uint8Array |
socket.onClose = function() {
// handle socket close
};
socket.onError = function(error) {
// handle socket error
};
Name | Type |
---|---|
error | unknown |
await socket.open(host, port);
Name | Type |
---|---|
host | String |
port | Number |
await socket.write(data);
Name | Type |
---|---|
data | Uint8Array |
await socket.close();
Q: When I call the open method after being disconnected, I will be prompted that the open method can only be called once. How should I reconnect?
A: To re-connect the socket you should create the new one and open it.