@deno-plc/adapter-tcp@1.1.0Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
deno-plc/adapter-tcpBase adapter for devices that can be controlled via a TCP socket
Deno-PLC / Adapter-TCP
Base adapter for devices that can be controlled via a TCP socket
Installation
Usage
import { TCPAdapter, TCPAdapterCallback, TCPAdapterSession, } from "@deno-plc/adapter-tcp"; interface MyProtocolAdapterOptions { host: string; port?: number; verbose?: boolean; } class MyProtocolAdapter extends TCPAdapter { constructor(options: MyProtocolAdapterOptions) { super({ sessionFactory: (cb) => new MyProtocolAdapterSession(this, cb), port: 1234, label: `MyProtocol ${options.host}`, ...options, }); } } class MyProtocolAdapterSession implements TCPAdapterSession { constructor(readonly adapter: MyProtocolAdapter, send: TCPAdapterCallback) { this.#send = send; setTimeout(() => { // TX this.#send(new TextEncoder().encode("Hello")); }); } readonly #send: TCPAdapterCallback; recv(data: Uint8Array): void { // RX } destroy(): void { // cleanup } }
For more see examples/
Logging
All events (connect/disconnect/errors) can be logged with
logtape. You can disable it by setting
verbose = false
, simply not configuring logtape or setting a log level > info
for app
>deno-plc
>tcp
>[options.label]
License
Copyright (C) 2024 - 2025 Hans Schallmoser
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Built and signed on
GitHub Actions
Add Package
deno add jsr:@deno-plc/adapter-tcp
Import symbol
import * as adapter_tcp from "@deno-plc/adapter-tcp";
Import directly with a jsr specifier
import * as adapter_tcp from "jsr:@deno-plc/adapter-tcp";