A tcp socket plugin for capacitor
npm install cap-tcp-socket-pluginbash
npm install cap-tcp-socket-plugin
npx cap sync
`
API
sendAsync(...)
* startReceiving(...)
* stopReceiving()
* addListener('receiveData', ...)
* getCurrentIPAddress()
* Interfaces
* Enums
$3
`typescript
sendAsync(options: { ipAddress: string; port: number; data: number[]; connectionTimeoutInSec: number; }) => Promise<{ status: ResultStatus; message?: string; data?: number[]; }>
`Sends data over TCP to the specified IP address and port.
| Param | Type | Description |
| ------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------ |
|
options | { ipAddress: string; port: number; data: number[]; connectionTimeoutInSec: number; } | - Configuration for the TCP request. |Returns: Promise<{ status: ResultStatus; message?: string; data?: number[]; }>
--------------------
$3
`typescript
startReceiving(options: { port: number; }) => Promise
`| Param | Type |
| ------------- | ------------------------------ |
|
options | { port: number; } |--------------------
$3
`typescript
stopReceiving() => Promise
`--------------------
$3
`typescript
addListener(eventName: "receiveData", listener: (data: { status: string; data: number[]; }) => void) => Promise
`Adds a listener for the 'receiveData' event.
| Param | Type | Description |
| --------------- | ------------------------------------------------------------------- | ------------------------------------------------------ |
|
eventName | 'receiveData' | - The name of the event (in this case, 'receiveData'). |
| listener | (data: { status: string; data: number[]; }) => void | - The callback function to handle the event. |Returns: Promise<PluginListenerHandle>
--------------------
$3
`typescript
getCurrentIPAddress() => Promise<{ ipAddress: string; }>
`Retrieves the current IP address of the device.
Returns: Promise<{ ipAddress: string; }>
--------------------
$3
#### PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
|
remove | () => Promise<void> |
$3
#### ResultStatus
| Members | Value |
| ------------------------------------- | -------------- |
|
Unknown | 0 |
| Success | 1 |
| FailedToSendData | 2 |
| NoResponseReceivedWithinTimeout | 3 |
| FailedToReceiveData` | 4 |