diff options
author | Zachary Dremann <dremann@gmail.com> | 2014-06-09 16:06:32 -0400 |
---|---|---|
committer | Zachary Dremann <dremann@gmail.com> | 2014-06-09 16:06:32 -0400 |
commit | 6eac9deb6231ee345d2d19f54761a4820f0c345b (patch) | |
tree | 42fb80e85eba4cde60d892ea0f2e88a56222123d /examples | |
parent | 937a4fe1fb42a09c7dff0c6a117f97c40bb8f734 (diff) | |
download | rusty-irc-6eac9deb6231ee345d2d19f54761a4820f0c345b.tar.gz rusty-irc-6eac9deb6231ee345d2d19f54761a4820f0c345b.zip |
tmp
Diffstat (limited to 'examples')
-rw-r--r-- | examples/client.rs | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/examples/client.rs b/examples/client.rs index 6ec9134..d37bb40 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -1,25 +1,27 @@ extern crate irc; -use std::io::net::tcp::TcpStream; -use std::io::BufferedReader; +use std::io::stdio; -use irc::IrcConnection; +use irc::IrcClient; use irc::msg::Message; -use irc::msg::cmd; +//use irc::msg::cmd; fn main() { - let message = Message { - prefix: None, - command: cmd::PrivMsg("#rust".to_string(), "Hi there everyone".to_string()), - }; - - println!("{}", message); + let mut stderr = stdio::stderr(); + + let mut args = std::os::args().move_iter(); + args.next(); + let host = args.next().expect("No hostname passed"); + let port: u16 = from_str(args.next().unwrap_or_else(|| { let _ = writeln!(stderr, "No port given. Assuming 6667."); "6667".to_string() }).as_slice()) + .expect("Port must be a number"); + + drop(args); - let on_msg = |message: &Message, _sender: &Sender<Message>| { + let mut connection = IrcClient::connect(host.as_slice(), port, "Dr-Emann".to_string(), "dremann".to_string(), "Zachary Dremann".to_string()).unwrap(); + + let on_msg = |message: &Message| { println!("{}", *message); }; - let mut connection = IrcConnection::connect("irc.mozilla.org", 6667, "Dr-Emann".to_string(), "dremann".to_string(), "Zachary Dremann".to_string(), on_msg).unwrap(); - - connection.run_loop(); + connection.run_loop(on_msg); } |