Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Three Byte

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
241 changes: 150 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,121 +1,180 @@
# Network Communication Library
# 🔗 ThreeByte.LinkLib

## Overview
The Network Communication Library provides a simple and efficient way to handle network communication using TCP, UDP, and Serial protocols. This library is designed to be easy to use and integrate into your projects, offering robust and reliable communication capabilities. /
**A family of .NET communication libraries for TCP, UDP, Serial, projector control (PJLink), and networked power management (NetBooter).**

## Features
- **TCP Communication**: Establish and manage TCP connections for reliable data transfer.
- **UDP Communication**: Send and receive data using the UDP protocol for low-latency communication.
- **Serial Communication**: Interface with serial devices for data exchange.
- **Asynchronous Support**: Fully supports asynchronous operations for non-blocking communication.
- **Cross-Platform**: Compatible with .NET Standard 2.1, making it usable across different platforms.
[![.NET](https://img.shields.io/badge/.NET-10.0%20%7C%20Standard%202.0%20%7C%20Standard%202.1-purple?logo=dotnet)](https://dotnet.microsoft.com)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![NuGet](https://img.shields.io/badge/NuGet-published-blue?logo=nuget)](https://www.nuget.org/profiles/olaaf)

---

## 📦 Packages

| Package | NuGet | Description |
|---------|-------|-------------|
| 🌐 [**TcpLink**](ThreeByte.LinkLib/ThreeByte.LinkLib.TcpLink/) | [![NuGet](https://img.shields.io/nuget/v/ThreeByte.LinkLib.TcpLink?color=blue&logo=nuget)](https://www.nuget.org/packages/ThreeByte.LinkLib.TcpLink) | Async TCP client with auto-reconnect and message queuing |
| 📡 [**UdpLink**](ThreeByte.LinkLib/ThreeByte.LinkLib.UdpLink/) | [![NuGet](https://img.shields.io/nuget/v/ThreeByte.LinkLib.UdpLink?color=blue&logo=nuget)](https://www.nuget.org/packages/ThreeByte.LinkLib.UdpLink) | Async UDP client with configurable local/remote endpoints |
| 🔌 [**SerialLink**](ThreeByte.LinkLib/ThreeByte.LinkLib.SerialLink/) | [![NuGet](https://img.shields.io/nuget/v/ThreeByte.LinkLib.SerialLink?color=blue&logo=nuget)](https://www.nuget.org/packages/ThreeByte.LinkLib.SerialLink) | RS-232 serial communication with optional frame-based protocol |
| 🎬 [**ProjectorLink**](ThreeByte.LinkLib/ThreeByte.LinkLib.ProjectorLink/) | [![NuGet](https://img.shields.io/nuget/v/ThreeByte.LinkLib.ProjectorLink?color=blue&logo=nuget)](https://www.nuget.org/packages/ThreeByte.LinkLib.ProjectorLink) | PJLink protocol client for projector power control and queries |
| 🔋 [**NetBooter**](ThreeByte.LinkLib/ThreeByte.LinkLib.NetBooter/) | [![NuGet](https://img.shields.io/nuget/v/ThreeByte.LinkLib.NetBooter?color=blue&logo=nuget)](https://www.nuget.org/packages/ThreeByte.LinkLib.NetBooter) | Synaccess NetBooter networked power outlet controller |
| 🧩 [**Shared**](ThreeByte.LinkLib/ThreeByte.LinkLib.Shared/) | [![NuGet](https://img.shields.io/nuget/v/ThreeByte.LinkLib.Shared?color=blue&logo=nuget)](https://www.nuget.org/packages/ThreeByte.LinkLib.Shared) | Shared logging infrastructure (auto-included as dependency) |

---

## ✨ Features

- **Asynchronous** — Non-blocking I/O across all transport layers
- **Thread-Safe** — Lock-protected operations for concurrent access
- **Message Queuing** — FIFO queues (up to 100 messages) for reliable retrieval
- **Event-Driven** — Rich events for connection changes, data arrival, and errors
- **Auto-Reconnect** — TCP and Serial links recover automatically from failures
- **Cross-Platform** — Targets .NET 10.0, .NET Standard 2.0, and .NET Standard 2.1

---

## 📥 Installation

Install only the packages you need:

## Installation
To install the library, use the following command in the NuGet Package Manager Console:
```powershell
Install-Package ThreeByte.LinkLib.TcpLink
Install-Package ThreeByte.LinkLib.UdpLink
Install-Package ThreeByte.LinkLib.SerialLink
dotnet add package ThreeByte.LinkLib.TcpLink
dotnet add package ThreeByte.LinkLib.UdpLink
dotnet add package ThreeByte.LinkLib.SerialLink
dotnet add package ThreeByte.LinkLib.ProjectorLink
dotnet add package ThreeByte.LinkLib.NetBooter
```

## Usage
---

## 🚀 Quick Start

### TCP — Connect to a device

### TCP Communication
```csharp
using ThreeByte.LinkLib.TcpLink;
using System;
using System.Threading.Tasks;

class Program
{
static async Task Main(string[] args)
{
var server = new TcpServer("0.0.0.0", 8080);
server.Start();
while (true)
{
var clientSocket = await server.AcceptConnectionAsync();
var data = await server.ReceiveDataAsync(clientSocket);
Console.WriteLine("Received: " + data);
await server.SendDataAsync(clientSocket, "Hello, Client!");
server.CloseConnection(clientSocket);
}
server.Stop();
}
}

var tcp = new AsyncTcpLink("192.168.1.100", 5000);
tcp.DataReceived += (s, e) => Console.WriteLine($"Got {tcp.GetMessage()?.Length} bytes");

byte[] cmd = System.Text.Encoding.ASCII.GetBytes("HELLO\r\n");
tcp.SendMessage(cmd);
```

### UDP Communication
### UDP — Fire-and-forget datagrams

```csharp
using ThreeByte.LinkLib.UdpLink;
using System;
using System.Threading.Tasks;

class Program
{
static async Task Main(string[] args)
{
var client = new UdpClient("127.0.0.1", 8080);
await client.SendDataAsync("Hello, Server!");
var response = await client.ReceiveDataAsync();
Console.WriteLine("Server response: " + response);
}
}

var udp = new AsyncUdpLink("192.168.1.50", remotePort: 9000, localPort: 9001);
udp.SendMessage(System.Text.Encoding.ASCII.GetBytes("PING"));
```

### Serial Communication
### Serial — Talk to RS-232 devices

```csharp
using ThreeByte.LinkLib.SerialLink;
using System;
using System.Threading.Tasks;

class Program
{
static async Task Main(string[] args)
{
var serial = new SerialComm("/dev/ttyUSB0", 9600);
await serial.OpenAsync();
await serial.SendDataAsync("Hello, Device!");
var response = await serial.ReceiveDataAsync();
Console.WriteLine("Device response: " + response);
serial.Close();
}
}

var serial = new SerialLink("COM3", baudRate: 9600);
serial.SendData(new byte[] { 0x01, 0x02, 0x03 });
```

### Projector — PJLink power control

```csharp
using ThreeByte.LinkLib.ProjectorLink;

using var projector = new Projector("192.168.1.200");
projector.TurnOn();
PowerStatus status = projector.GetState();
string info = projector.GetInfo(); // "Epson EB-L1755U (Main Hall)"
```

### NetBooter — Remote power outlet control

```csharp
using ThreeByte.LinkLib.NetBooter;

var netBooter = new NetBooterLink("192.168.1.10");
netBooter.Power(outlet: 1, state: true); // Turn on outlet 1
netBooter.PollState();
bool isOn = netBooter[1]; // Check outlet state
```

---

## 🏗️ Architecture

```mermaid
graph TD
App["🖥️ Your Application"]

App --> TCP["🌐 TcpLink<br/><i>Async TCP Client</i>"]
App --> UDP["📡 UdpLink<br/><i>Async UDP Client</i>"]
App --> Serial["🔌 SerialLink<br/><i>RS-232 Communication</i>"]
App --> Projector["🎬 ProjectorLink<br/><i>PJLink Protocol</i>"]
App --> NetBooter["🔋 NetBooter<br/><i>HTTP Power Control</i>"]

TCP --> Shared["🧩 Shared<br/><i>LogFactory · Logging</i>"]
UDP --> Shared
Serial --> Shared
Projector --> Shared
NetBooter --> Shared

style App fill:#4a90d9,stroke:#2c5f8a,color:#fff
style TCP fill:#6c5ce7,stroke:#4a3db5,color:#fff
style UDP fill:#6c5ce7,stroke:#4a3db5,color:#fff
style Serial fill:#6c5ce7,stroke:#4a3db5,color:#fff
style Projector fill:#e17055,stroke:#b5553f,color:#fff
style NetBooter fill:#e17055,stroke:#b5553f,color:#fff
style Shared fill:#00b894,stroke:#009472,color:#fff
```

## How to Build and Publish NuGet Packages using pipelines
---

To build and publish NuGet packages, follow these steps:
1. Create a new GitHub branch and switch to it
2. Update the source code in any of the following `ThreeByte.LinkLib` folders:
- ThreeByte.LinkLib.SerialLink
- ThreeByte.LinkLib.TcpLink
- ThreeByte.LinkLib.UdpLink
## 📋 How to Build and Publish NuGet Packages

**Note:** The pipeline will only be triggered when changes are made in these folders
1. Create a new branch and make your changes in any `ThreeByte.LinkLib.*` folder
2. Commit and push to GitHub
3. Create a pull request to `main` and attach a label:
- `major` — breaking changes
- `minor` — new features
- `patch` — bug fixes

3. Commit and push your changes to the GitHub repository.
4. Create a pull request to the main branch and attach one of the following labels based on the type of change you made:
- major
- minor
- patch
> We follow [Semantic Versioning](https://semver.org/)

**Note:** The version of the new NuGet package is determined by the attached label. We follow [Semantic Versioning](https://semver.org/)
4. Merge your pull request
5. Your NuGet package will be available on [nuget.org](https://www.nuget.org/profiles/olaaf) within ~5 minutes

5. Merge your pull request
6. Wait approximately 5 minutes — your NuGet package will then be available on [nuget.org](https://www.nuget.org/profiles/olaaf)
---

## 🤝 Contributing

## Contributing
Contributions are welcome! Please fork the repository and submit a pull request with your changes.

## License
...
---

## Contact
For any questions or issues, please contact us at `support@mail`.
```
Feel free to customize this example to better fit your specific library and its features!
If you have any other questions or need further assistance, let me know.
```
## 📄 License

This project is licensed under the MIT License — see the [LICENSE](LICENSE) file for details.

MIT License

Copyright (c) 2025 Three Byte

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,4 @@ This library implements the [PJLink](https://pjlink.jbmia.or.jp/english/) Class

## 📄 License

Part of the [ThreeByte.LinkLib](https://github.com/olaafrossi/three-byte.link-lib) family of communication libraries.
Part of the [ThreeByte.LinkLib](https://github.com/Three-Byte/three-byte.link-lib) family of communication libraries.
2 changes: 1 addition & 1 deletion ThreeByte.LinkLib/ThreeByte.LinkLib.SerialLink/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,4 @@ var serial = new SerialLink(settings);

## 📄 License

Part of the [ThreeByte.LinkLib](https://github.com/olaafrossi/three-byte.link-lib) family of communication libraries.
Part of the [ThreeByte.LinkLib](https://github.com/Three-Byte/three-byte.link-lib) family of communication libraries.
2 changes: 1 addition & 1 deletion ThreeByte.LinkLib/ThreeByte.LinkLib.Shared/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ warn: MyApp.DeviceController[0]

## 📄 License

Part of the [ThreeByte.LinkLib](https://github.com/olaafrossi/three-byte.link-lib) family of communication libraries.
Part of the [ThreeByte.LinkLib](https://github.com/Three-Byte/three-byte.link-lib) family of communication libraries.
2 changes: 1 addition & 1 deletion ThreeByte.LinkLib/ThreeByte.LinkLib.TcpLink/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ var settings = new TcpLinkSettings("192.168.1.100", 5000);

## 📄 License

Part of the [ThreeByte.LinkLib](https://github.com/olaafrossi/three-byte.link-lib) family of communication libraries.
Part of the [ThreeByte.LinkLib](https://github.com/Three-Byte/three-byte.link-lib) family of communication libraries.
Loading