Compare commits

...

7 commits

Author SHA1 Message Date
9cbbaca88a
fix listen bound ip 2022-02-05 18:30:46 +01:00
d9a17a6464
Update lib.rs 2021-07-05 15:10:56 +02:00
9c3d94f581
Update lib.rs 2021-07-05 15:07:02 +02:00
c3e4016547 Merge remote-tracking branch 'origin/master' into master 2021-05-11 15:09:28 +02:00
fccb89b725 better prints 2021-05-11 15:09:21 +02:00
9071bd370c
Update README.md 2021-05-11 14:57:46 +02:00
70bbde046b
Create README.md 2021-05-11 14:56:33 +02:00
3 changed files with 17 additions and 6 deletions

11
README.md Normal file
View file

@ -0,0 +1,11 @@
# 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.

View file

@ -9,9 +9,9 @@ type StreamResult = Result<TcpStream, Box<dyn Error>>;
pub fn listen() -> StreamResult {
println!("Listening on {}:8080", local_ipaddress::get().unwrap());
let listener = TcpListener::bind(("127.0.0.1", 8080))?;
let listener = TcpListener::bind(("0.0.0.0", 8080))?;
let stream = listener.incoming().next().unwrap()?;
println!("Connected. Waiting for response stream...");
println!("Connected.");
println!("other adress: {}", stream.peer_addr()?.ip());
Ok(stream)
@ -24,6 +24,7 @@ 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)
}
@ -44,6 +45,7 @@ pub fn network_thread(mut stream: TcpStream, rx: Receiver<String>) {
}
pub fn ui_thread(sx: Sender<String>) {
println!("You can now write messages to your peer!");
loop {
let input = input();
sx.send(input).expect("could not send value");

View file

@ -16,9 +16,9 @@ fn main() {
Version 0.1"
);
println!("Do you want to listen(l) or connect(c) to a listener?");
println!("Do you want to (l)isten or (c)onnect to a listener?");
let result = if input().contains("l") {
let result = if input() == "l" {
listen()
} else {
println!("Address: (empty for default)");
@ -36,8 +36,6 @@ Version 0.1"
match result {
Ok(s) => {
println!("Successful connection established.");
let (sx, rx): (Sender<String>, Receiver<String>) = mpsc::channel();
let net = thread::spawn(move || {