BlueProtocol 0.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package BlueProtocol --version 0.4.0                
NuGet\Install-Package BlueProtocol -Version 0.4.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlueProtocol" Version="0.4.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BlueProtocol --version 0.4.0                
#r "nuget: BlueProtocol, 0.4.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BlueProtocol as a Cake Addin
#addin nuget:?package=BlueProtocol&version=0.4.0

// Install BlueProtocol as a Cake Tool
#tool nuget:?package=BlueProtocol&version=0.4.0                

πŸ”΅ BlueProtocol

BlueProtocol is a C# library designed to provide a high-level interface for TCP communication, particularly recommended in domains where speed is a critical factor, not necessarily limited to video games. It offers a lightweight, bidirectional request system that maintains a persistent connection between peers to minimize response times. The library is currently being developed to function in a decentralized network.

❓ Why BlueProtocol and not HTTP?

HTTP, while widely used, is not optimized for real-time communication required in many video games. BlueProtocol provides a more efficient, low-latency communication mechanism tailored for interactive applications. By maintaining persistent connections and using lightweight requests and events, BlueProtocol reduces overhead and improves responsiveness.

βš™οΈ How does BlueProtocol work?

BlueProtocol allows communication between clients and servers through two main components: requests and events. Clients send requests for specific actions to the server, which processes these requests and sends back responses indicating success or failure. Events are used by the server to notify clients of changes, ensuring all clients remain synchronized.

πŸ”„ Async vs. Sync: Differences and Recommendations

  • AsyncClient: Used on the server-side, executes code asynchronously upon receiving a request using Task.Run
  • to avoid blocking the main thread.
  • SyncClient: Used on the client-side, stores incoming requests in a thread-safe list and processes them during the
  • Update call, making it suitable for Unity’s main thread.

πŸ’‘ Recommendation:

Use AsyncClient for server-side operations to handle multiple client requests efficiently without blocking. UseSyncClient on the client-side to ensure smooth integration with Unity’s single-threaded update loop.

πŸ”— Communication Between Peers

  1. Requests: A client sends a request to the server to perform an action.
  2. The server processes the request and returns a response.
  3. Events: The server sends events to clients to notify them of changes or updates (e.g., a game element moving).
  4. Clients handle these events to stay synchronized.

πŸ“€ Requests vs. Events

  • Request: A message sent from a client to the server that expects a response. Used for actions where confirmation is needed.
  • Event: A one-way message sent from the server to clients. No response is expected. Used for notifications or updates.

πŸ•ΉοΈ What is a Controller and How Does it Work?

A Controller is a class that handles specific types of requests and events. It contains methods marked with [OnRequest] or [OnEvent] attributes to process incoming messages. When a request or event is received, the corresponding method in the controller is invoked to handle it.


πŸ“¦ Installation

To install the BlueProtocol library, follow these steps:

  1. Using .NET CLI: Run the following command to add the BlueProtocol package to your project.

    dotnet add package BlueProtocol --version latest
    
  2. Using GitHub Releases: Visit the Releases page on the BlueProtocol GitHub repository. Download the latest release package and follow the instructions provided in the release notes to add it to your project manually.

These methods ensure that you have the latest version of BlueProtocol installed and ready to use in your .NET project.


πŸ“š Example Projects

SimpleCount

SimpleCount demonstrates the use of the BlueProtocol library for TCP communication between a server and a client. The server listens for incoming messages and logs each received message, while the client sends a series of count requests to the server.

SimpleCount Documentation

SimpleRepeat

SimpleRepeat demonstrates the use of the BlueProtocol library for TCP communication between multiple "bots". Each bot connects directly to other bots, sends and receives messages, and prints the received messages to the console via a port scan starting from the StartingPort defined in the configuration.

SimpleRepeat Documentation

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.5.1 131 7/3/2024
0.4.0 100 7/2/2024

[+] Server-side shields