diff --git a/README.md b/README.md deleted file mode 100644 index ba49a81..0000000 --- a/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# terminal-chat -Peer-to-peer DM Terminal chat - -## How to use it -Just start the program, then either (l)isten or (c)onnect, one person has to listen and then the other one has to connect to it. -The port is always 8080 for now, and the listeners ip address is shown for the listener, so it can easily be seen. -Then just write and the messages of the other person are shown in your terminal! - -## Debugging -If it doesn't work, make sure that you connected to the correct ip address and port, and make sure that your firewall allows connections on port 8080 for this program. -If it still doesn't work open an issue. diff --git a/src/lib.rs b/src/lib.rs index 90297fa..330b026 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,9 +9,9 @@ type StreamResult = Result>; pub fn listen() -> StreamResult { println!("Listening on {}:8080", local_ipaddress::get().unwrap()); - let listener = TcpListener::bind(("0.0.0.0", 8080))?; + let listener = TcpListener::bind(("127.0.0.1", 8080))?; let stream = listener.incoming().next().unwrap()?; - println!("Connected."); + println!("Connected. Waiting for response stream..."); println!("other adress: {}", stream.peer_addr()?.ip()); Ok(stream) @@ -24,7 +24,6 @@ pub fn connect(address: String, port: String) -> StreamResult { let stream = TcpStream::connect((&*address, port))?; println!("Connected."); - println!("other adress: {}", stream.peer_addr()?.ip()); Ok(stream) } @@ -45,7 +44,6 @@ pub fn network_thread(mut stream: TcpStream, rx: Receiver) { } pub fn ui_thread(sx: Sender) { - println!("You can now write messages to your peer!"); loop { let input = input(); sx.send(input).expect("could not send value"); diff --git a/src/main.rs b/src/main.rs index b9114b6..fda4a66 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,9 +16,9 @@ fn main() { Version 0.1" ); - println!("Do you want to (l)isten or (c)onnect to a listener?"); + println!("Do you want to listen(l) or connect(c) to a listener?"); - let result = if input() == "l" { + let result = if input().contains("l") { listen() } else { println!("Address: (empty for default)"); @@ -36,6 +36,8 @@ Version 0.1" match result { Ok(s) => { + println!("Successful connection established."); + let (sx, rx): (Sender, Receiver) = mpsc::channel(); let net = thread::spawn(move || {