Added portwhisper.rs
This little bit of ChatGPT code here opens port 4000 (the client-to-server port we're thinking of) and takes a bunch of variables in an array and tells them to the server or as we nicknamed It - whispering to the server.
This commit is contained in:
parent
ad204d06e9
commit
cafd444799
2 changed files with 26 additions and 42 deletions
to_be_implemented?
|
@ -1,42 +0,0 @@
|
||||||
use std::io::Write;
|
|
||||||
use std::net::{TcpListener, TcpStream};
|
|
||||||
use std::thread;
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
fn handle_client(mut stream: TcpStream) {
|
|
||||||
let mut counter = 0;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
let variables = [counter, counter + 1, counter + 2];
|
|
||||||
let serialized_data = format!("{:?}\n", variables);
|
|
||||||
|
|
||||||
if let Err(e) = stream.write_all(serialized_data.as_bytes()) {
|
|
||||||
eprintln!("Failed to send data: {}", e);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Sent: {:?}", variables);
|
|
||||||
counter += 1;
|
|
||||||
thread::sleep(Duration::from_secs(1)); // Delay to avoid spamming
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
|
||||||
let listener = TcpListener::bind("0.0.0.0:4000")?;
|
|
||||||
println!("Server listening on port 4000");
|
|
||||||
|
|
||||||
for stream in listener.incoming() {
|
|
||||||
match stream {
|
|
||||||
Ok(stream) => {
|
|
||||||
println!("New connection: {}", stream.peer_addr().unwrap());
|
|
||||||
thread::spawn(|| handle_client(stream));
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("Connection failed: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
26
to_be_implemented?/portwhisper.rs
Normal file
26
to_be_implemented?/portwhisper.rs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
use std::net::UdpSocket;
|
||||||
|
use std::thread::sleep;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
fn main() -> std::io::Result<()> {
|
||||||
|
// Create a UDP socket bound to port 4000
|
||||||
|
let socket = UdpSocket::bind("0.0.0.0:0")?;
|
||||||
|
let target = "127.0.0.1:4000"; // Target address and port
|
||||||
|
|
||||||
|
// Data to send
|
||||||
|
let data = [1, 2, 3, 4, 5]; // Example array of variables
|
||||||
|
|
||||||
|
println!("Sending data to {}...", target);
|
||||||
|
|
||||||
|
loop {
|
||||||
|
// Serialize the data into a byte string
|
||||||
|
let serialized_data = format!("{:?}\n", data);
|
||||||
|
// Send the data to the target
|
||||||
|
if let Err(e) = socket.send_to(serialized_data.as_bytes(), target) {
|
||||||
|
eprintln!("Failed to send data: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pause for 1 second
|
||||||
|
sleep(Duration::from_secs(1));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue