fixed at least zero things
This commit is contained in:
parent
3a5b9ce46a
commit
1b3d87e9a6
19
README.md
Normal file
19
README.md
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Sunbeam TCP Relay v0.1
|
||||||
|
#### Elizabeth Evelene Amelia Diode, June 2019
|
||||||
|
#### AGPL v3
|
||||||
|
|
||||||
|
### Oh no, what is it this time?
|
||||||
|
Sunbeam is a simple and fast multi-endpoint TCP relay for
|
||||||
|
for um
|
||||||
|
we swear we had a perfectly reasonable use in mind but we honestly can't remember it now.
|
||||||
|
|
||||||
|
Basically it just lets clients connect from anywhere, takes data from them, and redistributes
|
||||||
|
it to all the other connected clients. It's written with an asynchronous structure and
|
||||||
|
nonblocking I/O, meaning it should be pretty fast, ideally fast enough to handle audio streams
|
||||||
|
and stuff.
|
||||||
|
|
||||||
|
We originally envisioned this as a similar (and similarly-cursed) project to Epistlebox, which
|
||||||
|
would play the role of an online chat platform to complement the other's terrible imitation of
|
||||||
|
email. You can indeed use it for that purpose, e.g. by running
|
||||||
|
`nc [server address] 55555`
|
||||||
|
on each of the clients, typing messages, and pressing enter.
|
20
sunbeam.rs
20
sunbeam.rs
|
@ -23,7 +23,7 @@ fn main() {
|
||||||
listener.set_nonblocking(true).expect("cannot set listener to nonblocking");
|
listener.set_nonblocking(true).expect("cannot set listener to nonblocking");
|
||||||
|
|
||||||
let mut connections:VecDeque<(TcpStream,SocketAddr)> = VecDeque::new();
|
let mut connections:VecDeque<(TcpStream,SocketAddr)> = VecDeque::new();
|
||||||
let mut bottle:[u8;1] = [0x00];
|
let mut bottle:[u8;512] = [0x00;512];
|
||||||
let mut idlecycles:usize = 0;
|
let mut idlecycles:usize = 0;
|
||||||
|
|
||||||
'processor:loop {
|
'processor:loop {
|
||||||
|
@ -56,21 +56,9 @@ fn main() {
|
||||||
0 => {
|
0 => {
|
||||||
println!("- connection to {} closed: read reached end of stream",address);
|
println!("- connection to {} closed: read reached end of stream",address);
|
||||||
},
|
},
|
||||||
_ => {
|
n => {
|
||||||
for _ in 0..connections.len() {
|
for (otherstream,_otheraddress) in connections.iter_mut() {
|
||||||
if let Some((mut otherstream,otheraddress)) = connections.pop_front() {
|
let _ = otherstream.write_all(&bottle[..n]);
|
||||||
match otherstream.write(&bottle) {
|
|
||||||
Err(why) => println!("- connection to {} failed: write error: {}",otheraddress,why),
|
|
||||||
Ok(n) => match n {
|
|
||||||
0 => {
|
|
||||||
println!("- connection to {} closed: write reached end of stream",otheraddress);
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
connections.push_back((otherstream,otheraddress));
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
connections.push_back((stream,address));
|
connections.push_back((stream,address));
|
||||||
idlecycles = 0;
|
idlecycles = 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user