Periodic websocket sends are now working

This commit is contained in:
Dave Hrycyszyn
2024-05-29 17:29:20 +01:00
parent f6b5825cea
commit fff4bfe9ee
5 changed files with 1340 additions and 16 deletions

1328
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -7,5 +7,14 @@ edition = "2021"
[dependencies] [dependencies]
clap = { version = "4.5.4", features = ["derive"] } clap = { version = "4.5.4", features = ["derive"] }
tokio = "*" tokio = { version = "1.37.0", features = ["time"] }
websockets = "0.3.0" websockets = "0.3.0"
bft-json-crdt = { path = "../../bft-json-crdt" }
bft-crdt-derive = { path = "../../bft-json-crdt/bft-crdt-derive" }
[features]
default = ["bft", "logging-list", "logging-json"]
logging-list = ["logging-base"]
logging-json = ["logging-base"]
logging-base = []
bft = []

View File

View File

@@ -1,3 +1,4 @@
use bft_json_crdt::keypair::make_keypair;
use cli::{parse_args, Commands}; use cli::{parse_args, Commands};
pub(crate) mod cli; pub(crate) mod cli;
@@ -13,7 +14,8 @@ async fn main() {
init::init(); init::init();
} }
Some(Commands::Run {}) => { Some(Commands::Run {}) => {
websocket::start().await.unwrap(); let keys = make_keypair();
websocket::start(keys).await.unwrap();
} }
None => println!("No command provided. Exiting. See --help for more information."), None => println!("No command provided. Exiting. See --help for more information."),
} }

View File

@@ -1,13 +1,18 @@
use bft_json_crdt::keypair::Ed25519KeyPair;
use tokio::time::{self};
use websockets::WebSocket; use websockets::WebSocket;
pub(crate) async fn start() -> Result<(), websockets::WebSocketError> { /// Starts a websocket and periodically sends a BFT-CRDT message to the websocket server
pub(crate) async fn start(keys: Ed25519KeyPair) -> Result<(), websockets::WebSocketError> {
let mut ws = WebSocket::connect("ws://localhost:8080/").await?; let mut ws = WebSocket::connect("ws://localhost:8080/").await?;
ws.send_text("foo".to_string()).await?; let mut interval = time::interval(time::Duration::from_secs(2));
// ws.receive().await?;
// ws.close(None).await?;
loop { loop {
interval.tick().await;
println!("Sending: period");
ws.send_text("period".to_string()).await?;
let msg = ws.receive().await?; let msg = ws.receive().await?;
println!("Received: {:?}", msg); println!("Received: {:?}", msg);
} }
} }