Browse Source

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/bin/client.rs
Key-exchange
Niklas Eichenseer 2 years ago
parent
commit
ed06a50aa8
3 changed files with 111 additions and 6 deletions
  1. 74
    0
      .gitignore
  2. 8
    5
      src/bin/client.rs
  3. 29
    1
      src/bin/server.rs

+ 74
- 0
.gitignore View File

@@ -59,3 +59,77 @@ Icon
Network Trash Folder
Temporary Items
.apdisk

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser


+ 8
- 5
src/bin/client.rs View File

@@ -10,14 +10,17 @@ fn main() {

loop {
let mut buffer = String::new();
match std::io::stdin().read_line(&mut buffer){
Ok(_n) => {
match std::io::stdin().read_line(&mut buffer) {
Ok(n) => {
if n == 0 {
break;
}
println!("Sending {}", buffer);
stream.write(buffer.as_bytes()).unwrap();
println!("Sent {}, awaiting reply...", buffer);
}
Err(_error) =>{
println!("Fehlerhafte Eingabe!");
Err(error) => {
println!("error: {error}");
break;
}
}
@@ -28,4 +31,4 @@ fn main() {
}
}
println!("Terminated.");
} // the stream is closed here
} // the stream is closed here

+ 29
- 1
src/bin/server.rs View File

@@ -1,3 +1,31 @@
use std::{
io::{prelude::*, BufReader},
net::{TcpListener, TcpStream},
};
use std::io::Lines;

fn main() {
println! ("server");
let listener = TcpListener::bind("127.0.0.1:7878").unwrap();

for stream in listener.incoming() {
let stream = stream.unwrap();

handle_connection(stream);
}
}

fn handle_connection(mut stream: TcpStream) {
let mut stream2: TcpStream = stream.try_clone().unwrap();
let buf_reader: BufReader<&mut TcpStream> = BufReader::new(&mut stream);
let request: Lines<BufReader<&mut TcpStream>> = buf_reader.lines();

println!("Request: {:#?}", request);

for elem in request
{
let s = elem.unwrap();
println!("{:?}", s);
stream2.write(s.as_bytes()).unwrap();
stream2.write_all(b"\n").unwrap();
}
}

Loading…
Cancel
Save