mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
add tcp connection class and example
This commit is contained in:
parent
74a784a253
commit
3882904b43
2 changed files with 163 additions and 0 deletions
27
examples/tcp_connection.js
Normal file
27
examples/tcp_connection.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import TCPConnection from "../src/connection/tcp_connection.js";
|
||||
|
||||
// create tcp connection
|
||||
const connection = new TCPConnection("10.1.0.226", 5000);
|
||||
|
||||
// wait until connected
|
||||
connection.on("connected", async () => {
|
||||
|
||||
// we are now connected
|
||||
console.log(`Connected to: [${connection.host}:${connection.port}]`);
|
||||
|
||||
// log contacts
|
||||
const contacts = await connection.getContacts();
|
||||
for(const contact of contacts) {
|
||||
console.log(`Contact: ${contact.advName}`);
|
||||
}
|
||||
|
||||
// send message to public channel
|
||||
// await connection.sendChannelTextMessage(0, "test");
|
||||
|
||||
// disconnect
|
||||
connection.close();
|
||||
|
||||
});
|
||||
|
||||
// connect to meshcore device
|
||||
await connection.connect();
|
||||
Loading…
Add table
Add a link
Reference in a new issue