Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from vladdancer/master
Browse files Browse the repository at this point in the history
Added host, port (with default value) variables using cli program mode
  • Loading branch information
mvlabat committed Jul 30, 2019
2 parents 3f1e854 + 6a06d94 commit 65abed7
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
62 changes: 62 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pub_weight/Cargo.toml
Expand Up @@ -11,6 +11,7 @@ uuid = { version = "0.7.4", features = ["v4"] }
futures = "0.1.28"
bincode = "1.1.4"
failure = "0.1.5"
clap = "2.33.0"

[dependencies.pirust_common]
path = "../common"
25 changes: 22 additions & 3 deletions pub_weight/src/main.rs
Expand Up @@ -4,6 +4,7 @@ use futures::stream::Stream;
use mqtt::{control::variable_header::ConnectReturnCode, packet::*, Decodable, Encodable};
use tokio::{runtime, timer::Interval};
use uuid::Uuid;
use clap::{Arg, App as CliApp};

use std::{io::Write, net::TcpStream, time::Duration};

Expand All @@ -14,10 +15,28 @@ fn generate_client_id() -> String {
}

fn main() -> Result<(), Error> {
let server_addr = "192.168.1.44:1883";
let matches = CliApp::new("Pirust")
.version("0.1.0")
.arg(Arg::with_name("host")
.required(true)
.takes_value(true)
.index(1)
.help("Host name or IP of the MQTT Server (without port)")
)
.arg(Arg::with_name("port")
.required(false)
.takes_value(true)
.index(2)
.help("Port of the MQTT Server")
)
.get_matches();

println!("Connecting to {:?} ... ", server_addr);
let mut stream = TcpStream::connect(server_addr).unwrap();
let server_addr = matches.value_of("host").unwrap();
let server_port = matches.value_of("port").unwrap_or("1883");
let server_host = format!("{}:{}", server_addr, server_port);

println!("Connecting to {:?} ... ", server_host);
let mut stream = TcpStream::connect(server_host).unwrap();
println!("Connected!");

let client_id = generate_client_id();
Expand Down

0 comments on commit 65abed7

Please sign in to comment.