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

View File

View File

@@ -1,3 +1,4 @@
use bft_json_crdt::keypair::make_keypair;
use cli::{parse_args, Commands};
pub(crate) mod cli;
@@ -13,7 +14,8 @@ async fn main() {
init::init();
}
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."),
}

View File

@@ -1,13 +1,18 @@
use bft_json_crdt::keypair::Ed25519KeyPair;
use tokio::time::{self};
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?;
ws.send_text("foo".to_string()).await?;
// ws.receive().await?;
// ws.close(None).await?;
let mut interval = time::interval(time::Duration::from_secs(2));
loop {
interval.tick().await;
println!("Sending: period");
ws.send_text("period".to_string()).await?;
let msg = ws.receive().await?;
println!("Received: {:?}", msg);
}
}