### Start RFlow Server and Process Messages (Rust) Source: https://context7.com/roboplc/rflow/llms.txt Starts the default RFlow server on a specified TCP address, blocking the current thread. It handles incoming client connections, sends a greeting, and relays messages between clients and the application. This example also demonstrates sending periodic heartbeats and processing incoming data. ```rust use std::thread; use std::time::Duration; use rtsc::time::interval; fn main() -> Result<(), Box> { // Take the data channel before starting server let data_channel = rflow::take_data_channel()?; // Spawn server in a separate thread thread::spawn(move || { rflow::serve("127.0.0.1:4001").expect("Failed to start server"); }); // Send periodic messages to all connected clients thread::spawn(move || { for _ in interval(Duration::from_secs(5)) { rflow::send("heartbeat ping".to_string()); } }); // Process incoming messages from clients for data in data_channel { println!("Received from client: {}", data); rflow::send(format!("ACK: {}", data)); if data.trim() == "shutdown" { break; } } Ok(()) } ``` -------------------------------- ### RFlow Server and Client Example in Rust Source: https://github.com/roboplc/rflow/blob/main/README.md This Rust code demonstrates how to set up an RFlow server, send periodic messages, and process incoming data. It utilizes the `rflow` crate for communication and `rtsc` for interval timing. The example includes spawning threads for the server and message sending, and a loop to process received data. ```rust use std::{thread, time::Duration}; use rtsc::time::interval; fn main() -> Result<(), Box> { let data_channel = rflow::take_data_channel()?; thread::spawn(move || { rflow::serve("127.0.0.1:4001").expect("failed to start server"); }); thread::spawn(move || { for _ in interval(Duration::from_secs(5)) { rflow::send("ping".to_string()); } }); for data in data_channel { println!("Received data: {}", data); rflow::send(format!("command accepted: {}", data)); let command = data.trim(); if command == "quit" { break; } } Ok(()) } ``` -------------------------------- ### Install and Run rflow-chat CLI Source: https://context7.com/roboplc/rflow/llms.txt The `rflow-chat` is a terminal client application for RFlow servers. It allows users to connect to servers, send messages, and includes features for saving chat history and interface control. Installation is done via Cargo. ```bash # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # Install the chat client # ``` -------------------------------- ### Spawn RFlow Server and Get Data Channel (Rust) Source: https://context7.com/roboplc/rflow/llms.txt A convenience function that spawns the default RFlow server on a separate thread and returns the data channel receiver for processing incoming messages. This simplifies server setup and message handling in a single call. ```rust use std::time::Duration; fn main() -> Result<(), Box> { // Spawn server and get data channel in one call let data_channel = rflow::spawn("0.0.0.0:4001")?; println!("Server started, waiting for messages..."); for message in data_channel { println!("Received: {}", message); match message.trim() { "status" => rflow::send("System OK"), "temp" => rflow::send("Temperature: 42.5C"), "quit" => { rflow::send("Goodbye!"); break; } cmd => rflow::send(format!("Unknown command: {}", cmd)), } } Ok(()) } ``` -------------------------------- ### RFlow Chat Client Command-Line Options Source: https://context7.com/roboplc/rflow/llms.txt Demonstrates various command-line options for the rflow-chat client, including custom timeouts, command prefixes, and termination behavior. These options allow for flexible interaction with the RFlow server. ```bash # Connect with custom timeout (30 seconds) rflow-chat 127.0.0.1 --timeout 30 # Use custom command prefix (default is ":") rflow-chat 127.0.0.1 --command-prefix "/" # Terminate on disconnect (useful for scripts) rflow-chat 127.0.0.1 --terminate # Built-in commands (with default ":" prefix): # :q - Quit the application # :c - Clear the chat buffer # :w filename - Write chat buffer to file ``` -------------------------------- ### Create Custom RFlow Server Instance (Rust) Source: https://context7.com/roboplc/rflow/llms.txt Allows the creation of a custom RFlow server instance with configurable parameters such as timeout, queue sizes, and maximum client count. This is useful for scenarios requiring multiple servers or specific configurations beyond the default settings. ```rust use rflow::Server; use std::thread; use std::time::Duration; fn main() -> Result<(), Box> { // Create server with 10-second timeout let server = Server::new(Duration::from_secs(10)); // Configure server parameters server.set_max_clients(32)?; server.set_outgoing_queue_size(256)?; server.set_incoming_queue_size(64)?; // Take data channel before serving let data_channel = server.take_data_channel()?; let server_clone = server.clone(); thread::spawn(move || { server_clone.serve("127.0.0.1:4002").expect("Server error"); }); // Process messages using server instance for msg in data_channel { println!("Got: {}", msg); server.send(format!("Echo: {}", msg)); } Ok(()) } ``` -------------------------------- ### rflow::Client::connect_with_options - Configured Client Connection Source: https://context7.com/roboplc/rflow/llms.txt Establishes a synchronous connection to an RFlow server with custom connection options, including timeout and incoming queue size. ```APIDOC ## POST /connect/options ### Description Connects to an RFlow server with custom connection options, allowing configuration of connection timeout and the size of the incoming message queue. ### Method POST ### Endpoint /connect/options ### Parameters #### Query Parameters - **address** (string) - Required - The network address of the RFlow server (e.g., "192.168.1.100:4001"). #### Request Body - **options** (object) - Required - An object containing connection configuration options. - **timeout** (Duration) - Optional - The connection timeout duration. Defaults to 5 seconds. - **incoming_queue_size** (usize) - Optional - The size of the buffer for incoming messages. Defaults to a system-defined value. ### Request Example ```json { "timeout": "30s", "incoming_queue_size": 512 } ``` ### Response #### Success Response (200) - **client** (object) - An instance of the connected client. - **rx** (object) - A receiver for incoming messages. #### Response Example ```json { "client": "", "rx": "" } ``` ### Example Usage (Rust) ```rust use rflow::{Client, ConnectionOptions}; use std::time::Duration; fn main() -> Result<(), Box> { let options = ConnectionOptions::new() .timeout(Duration::from_secs(30)) .incoming_queue_size(512); let (client, rx) = Client::connect_with_options("192.168.1.100:4001", &options)?; // ... process messages ... Ok(()) } ``` ``` -------------------------------- ### Connect to RFlow Server (Synchronous) Source: https://context7.com/roboplc/rflow/llms.txt Establishes a synchronous connection to an RFlow server, returning a client instance and a receiver for incoming messages. It handles protocol handshake and message parsing automatically. The default timeout is 5 seconds. ```rust use rflow::{Client, Direction}; fn main() -> Result<(), Box> { // Connect with default options (5 second timeout) let (client, rx) = Client::connect("127.0.0.1:4001")?; // Send a command to the server client.try_send("status")?; // Receive and process messages for (direction, message) in rx { match direction { Direction::ServerToClient => { println!("Server says: {}", message); } Direction::ClientToServer => { println!("Echo from another client: {}", message); } Direction::Last => unreachable!(), } // Check connection status if !client.is_connected() { println!("Connection lost"); break; } } Ok(()) } ``` -------------------------------- ### Connect to RFlow Server with Options (Synchronous) Source: https://context7.com/roboplc/rflow/llms.txt Connects to an RFlow server using custom connection options, allowing configuration of timeout duration and the size of the incoming message queue. This provides more control over the client's behavior. ```rust use rflow::{Client, ConnectionOptions}; use std::time::Duration; use std::thread; fn main() -> Result<(), Box> { // Create custom connection options let options = ConnectionOptions::new() .timeout(Duration::from_secs(30)) // 30 second connection timeout .incoming_queue_size(512); // Large incoming buffer let (client, rx) = Client::connect_with_options("192.168.1.100:4001", &options)?; // Spawn receiver thread let client_clone = client.clone(); thread::spawn(move || { for (direction, msg) in rx { println!("[{}] {}", direction.as_char(), msg); } println!("Receiver stopped, connected: {}", client_clone.is_connected()); }); // Send commands client.try_send("get_sensors")?; thread::sleep(Duration::from_secs(1)); client.try_send("set_mode production")?; thread::sleep(Duration::from_secs(5)); Ok(()) } ``` -------------------------------- ### Connect to RFlow Server (Asynchronous with Tokio) Source: https://context7.com/roboplc/rflow/llms.txt Provides an asynchronous client implementation using Tokio for non-blocking operations. This requires the `async` feature to be enabled in the `rflow` dependency. It allows for concurrent handling of network events. ```rust // Cargo.toml: rflow = { version = "0.1", features = ["async"] } use rflow::ClientAsync; use rflow::ConnectionOptions; use std::time::Duration; #[tokio::main] async fn main() -> Result<(), Box> { let options = ConnectionOptions::new() .timeout(Duration::from_secs(10)) .incoming_queue_size(256); let (client, mut rx) = ClientAsync::connect_with_options( "127.0.0.1:4001", &options ).await?; // Spawn task to receive messages let client_status = client.clone(); tokio::spawn(async move { while let Ok((direction, msg)) = rx.recv().await { println!("[{}] {}", direction.as_char(), msg); } println!("Connection closed: {}", !client_status.is_connected()); }); // Send commands asynchronously client.try_send("async_command").await?; tokio::time::sleep(Duration::from_secs(1)).await; client.try_send("another_command").await?; // Keep running tokio::time::sleep(Duration::from_secs(30)).await; Ok(()) } ``` -------------------------------- ### rflow::ClientAsync - Async/Tokio Client Source: https://context7.com/roboplc/rflow/llms.txt Provides an asynchronous client implementation using Tokio for non-blocking operations. This requires the `async` feature to be enabled in the rflow crate. ```APIDOC ## POST /connect/async ### Description Establishes an asynchronous connection to an RFlow server using Tokio. This client is designed for non-blocking operations and requires the `async` feature to be enabled. ### Method POST ### Endpoint /connect/async ### Parameters #### Query Parameters - **address** (string) - Required - The network address of the RFlow server (e.g., "127.0.0.1:4001"). #### Request Body - **options** (object) - Optional - An object containing connection configuration options. - **timeout** (Duration) - Optional - The connection timeout duration. Defaults to 5 seconds. - **incoming_queue_size** (usize) - Optional - The size of the buffer for incoming messages. Defaults to a system-defined value. ### Request Example ```json { "timeout": "10s", "incoming_queue_size": 256 } ``` ### Response #### Success Response (200) - **client** (object) - An instance of the connected asynchronous client. - **rx** (object) - An asynchronous receiver for incoming messages. #### Response Example ```json { "client": "", "rx": "" } ``` ### Example Usage (Rust with Tokio) ```rust use rflow::ClientAsync; use rflow::ConnectionOptions; use std::time::Duration; #[tokio::main] async fn main() -> Result<(), Box> { let options = ConnectionOptions::new() .timeout(Duration::from_secs(10)) .incoming_queue_size(256); let (client, mut rx) = ClientAsync::connect_with_options("127.0.0.1:4001", &options).await?; tokio::spawn(async move { while let Ok((direction, msg)) = rx.recv().await { println!("[{}] {}", direction.as_char(), msg); } }); client.try_send("async_command").await?; tokio::time::sleep(Duration::from_secs(30)).await; Ok(()) } ``` ``` -------------------------------- ### rflow::Client::connect - Synchronous Client Connection Source: https://context7.com/roboplc/rflow/llms.txt Establishes a synchronous connection to an RFlow server. It returns a client instance and a receiver for incoming messages, automatically handling protocol handshake and message direction parsing. ```APIDOC ## POST /connect ### Description Connects to an RFlow server using default options (5-second timeout) and returns a client instance along with a receiver for incoming messages. The client automatically handles the protocol handshake and message direction parsing. ### Method POST ### Endpoint /connect ### Parameters #### Query Parameters - **address** (string) - Required - The network address of the RFlow server (e.g., "127.0.0.1:4001"). ### Request Body None ### Response #### Success Response (200) - **client** (object) - An instance of the connected client. - **rx** (object) - A receiver for incoming messages. #### Response Example ```json { "client": "", "rx": "" } ``` ### Example Usage (Rust) ```rust use rflow::{Client, Direction}; fn main() -> Result<(), Box> { let (client, rx) = Client::connect("127.0.0.1:4001")?; client.try_send("status")?; for (direction, message) in rx { match direction { Direction::ServerToClient => println!("Server says: {}", message), Direction::ClientToServer => println!("Echo from another client: {}", message), Direction::Last => unreachable!(), } if !client.is_connected() { println!("Connection lost"); break; } } Ok(()) } ``` ``` -------------------------------- ### RFlow Protocol Overview Source: https://github.com/roboplc/rflow/blob/main/protocol.md This section details the RFlow protocol, including its structure, message formats, and connection handling. ```APIDOC ## RFlow Protocol Description RFlow is a text-based protocol used for communication between a client and a server in the RoboPLC system. It is designed for simplicity and ease of implementation. ### Server Greeting Upon client connection, the server initiates communication with a greeting message: ``` RFLOW/1 [optional headers] --- ``` * `RFLOW/1`: Identifies the protocol name and its current version. * `[optional headers]`: A list of headers the server may send, formatted as `HEADER: VALUE`. * `---`: Marks the end of header transmission. ### Client to Server Messages Messages sent from the client to the server should be transmitted as a single line and are sent as-is. ### Server to Client Messages Messages from the server to the client are also single-line and are prefixed as follows: * `<<<`: Indicates a message originating from the server itself. * `>>>`: Indicates a message originating from the current client (echo) or another client. ### End of Connection The connection is terminated when the client disconnects. ``` -------------------------------- ### Server Greeting Message Format (RFlow Protocol) Source: https://github.com/roboplc/rflow/blob/main/protocol.md Defines the initial greeting message sent by the server to the client upon connection. It includes the protocol name/version and optional headers, followed by a separator. ```plaintext RFLOW/1 [optional headers] --- ``` -------------------------------- ### RFlow Cargo Full Feature Set Configuration Source: https://context7.com/roboplc/rflow/llms.txt Includes all available features for RFlow by specifying the 'full' feature in Cargo.toml. This enables all functionalities provided by the library. ```toml # Full feature set [dependencies] rflow = { version = "0.1", features = ["full"] } ``` -------------------------------- ### RFlow Cargo Feature Flags for Async Client Support Source: https://context7.com/roboplc/rflow/llms.txt Enables asynchronous client support for RFlow by specifying the 'async' feature in Cargo.toml. This allows integration with asynchronous runtimes like Tokio. ```toml # Enable async client support with Tokio [dependencies] rflow = { version = "0.1", features = ["async"] } ``` -------------------------------- ### RFlow Cargo Feature Flags for Locking Strategies Source: https://context7.com/roboplc/rflow/llms.txt Configures RFlow's locking strategies using Cargo feature flags in Cargo.toml. Options include default parking_lot locking, spin-free real-time locking, and priority-inheritance locking for Linux. ```toml # Cargo.toml examples # Default: parking_lot locking (suitable for most applications) [dependencies] rflow = "0.1" # Spin-free locking for real-time applications [dependencies] rflow = { version = "0.1", default-features = false, features = ["locking-rt"] } # Priority-inheritance locking (Linux only, prevents priority inversion) [dependencies] rflow = { version = "0.1", default-features = false, features = ["locking-rt-safe"] } ``` -------------------------------- ### Server to Client Message Prefixes (RFlow Protocol) Source: https://github.com/roboplc/rflow/blob/main/protocol.md Illustrates the prefixes used by the server to distinguish message origins. '<<<' indicates a server-originated message, while '>>>' indicates a message from a client (either the current one or another). ```plaintext <<< message from server >>> message from client ``` -------------------------------- ### rflow-chat - Terminal Client Application Source: https://context7.com/roboplc/rflow/llms.txt A command-line interface (CLI) chat client for RFlow servers, featuring built-in commands for managing chat history and controlling the user interface. ```APIDOC ## CLI Application: rflow-chat ### Description A dedicated terminal chat client application for interacting with RFlow servers. It supports saving chat history and provides basic interface controls. ### Installation ```bash cargo install rflow-chat ``` ### Usage Connect to an RFlow server: **Connect to server (default port 4001):** ```bash rflow-chat ``` Example: ```bash rflow-chat 127.0.0.1 ``` **Connect with explicit port:** ```bash rflow-chat : ``` Example: ```bash rflow-chat 192.168.1.100:4002 ``` ``` -------------------------------- ### RFlow Message Direction Enum Source: https://context7.com/roboplc/rflow/llms.txt The `Direction` enum in rflow represents the direction of messages within the RFlow protocol. It distinguishes between messages originating from the server and those echoed from other clients. Utility methods are provided for converting direction to string, char, or bytes. ```rust use rflow::Direction; fn format_message(direction: Direction, content: &str) -> String { match direction { Direction::ServerToClient => { // Messages prefixed with "<<<" from server format!("[SERVER] {}", content) } Direction::ClientToServer => { // Messages prefixed with ">>>" from clients (echo) format!("[CLIENT] {}", content) } Direction::Last => unreachable!(), // Internal use only } } // Direction utility methods fn example_direction_usage() { let dir = Direction::ServerToClient; println!("As string: {}", dir.as_str()); // Output: "<<<") println!("As char: {}", dir.as_char()); // Output: '<' println!("As bytes: {:?}", dir.as_bytes()); // Output: [60, 60, 60] println!("Display: {}", dir); // Output: "<<<") } ```