Compare commits
2 Commits
6904db79f0
...
db318bcf8a
| Author | SHA1 | Date | |
|---|---|---|---|
| db318bcf8a | |||
| bb626045a3 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,4 @@
|
|||||||
JustAMailProtocol/
|
JustAMailProtocol/
|
||||||
|
|
||||||
|
*.exe
|
||||||
|
*.pdb
|
||||||
20
jamp_client/.gitignore
vendored
Normal file
20
jamp_client/.gitignore
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/rust
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=rust
|
||||||
|
|
||||||
|
### Rust ###
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||||
|
Cargo.lock
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/rust
|
||||||
6
jamp_client/Cargo.toml
Normal file
6
jamp_client/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "jamp_client"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
14
jamp_client/src/main.rs
Normal file
14
jamp_client/src/main.rs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
use std::net::TcpStream;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
if let Ok(stream) = TcpStream::connect("127.0.0.1:8080") {
|
||||||
|
println!("Connected to the server!");
|
||||||
|
let ip_result = stream.peer_addr();
|
||||||
|
if ip_result.is_ok() {
|
||||||
|
println!("{}", ip_result.unwrap());
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Couldn't connect to server...");
|
||||||
|
}
|
||||||
|
}
|
||||||
20
jamp_server/.gitignore
vendored
Normal file
20
jamp_server/.gitignore
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/rust
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=rust
|
||||||
|
|
||||||
|
### Rust ###
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||||
|
Cargo.lock
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/rust
|
||||||
6
jamp_server/Cargo.toml
Normal file
6
jamp_server/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "jamp_server"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
29
jamp_server/src/main.rs
Normal file
29
jamp_server/src/main.rs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
use std::io::prelude::*;
|
||||||
|
use std::net::{TcpListener, TcpStream};
|
||||||
|
|
||||||
|
const IP: &str = "127.0.0.1:8080";
|
||||||
|
|
||||||
|
// https://doc.rust-lang.org/std/net/struct.TcpListener.html
|
||||||
|
fn handle_client(mut stream: TcpStream) {
|
||||||
|
let mut buffer = [0; 1024];
|
||||||
|
|
||||||
|
let read_result = stream.read(&mut buffer);
|
||||||
|
println!("read_result: {}", read_result.is_ok());
|
||||||
|
|
||||||
|
let shutdown_result = stream.shutdown(std::net::Shutdown::Both);
|
||||||
|
|
||||||
|
println!("shutdown_result: {}", shutdown_result.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://doc.rust-lang.org/std/net/struct.TcpListener.html
|
||||||
|
fn main() -> std::io::Result<()> {
|
||||||
|
let listener = TcpListener::bind(IP)?;
|
||||||
|
|
||||||
|
println!("Listening on {}", IP);
|
||||||
|
|
||||||
|
// accept connections and process them serially
|
||||||
|
for stream in listener.incoming() {
|
||||||
|
handle_client(stream?);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user