gold glory and god
This commit is contained in:
parent
fd5a815896
commit
6618429f88
|
@ -2,14 +2,41 @@ use tokio::net::TcpStream;
|
|||
use tokio::io::{AsyncWriteExt};
|
||||
use std::error::Error;
|
||||
|
||||
use alsa::{Direction, ValueOr};
|
||||
use alsa::pcm::{PCM, HwParams, Format, Access, State,};
|
||||
|
||||
use std::str;
|
||||
use std::ffi::CStr;
|
||||
use std::io::Read;
|
||||
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
// Connect to a peer
|
||||
let mut stream = TcpStream::connect("127.0.0.1:8080").await?;
|
||||
let mut _buffer = [0, 16];
|
||||
let mut buffer = [0u8, 1024];
|
||||
// Write some data.
|
||||
stream.write_all(b"hello world!").await?;
|
||||
let pcm = PCM::new("default", Direction::Playback, false).unwrap();
|
||||
|
||||
// Set hardware parameters: 44100 Hz / Mono / 16 bit
|
||||
let hwp = HwParams::any(&pcm).unwrap();
|
||||
hwp.set_channels(1).unwrap();
|
||||
hwp.set_rate(44100, ValueOr::Nearest).unwrap();
|
||||
hwp.set_format(Format::s16()).unwrap();
|
||||
hwp.set_access(Access::RWInterleaved).unwrap();
|
||||
pcm.hw_params(&hwp).unwrap();
|
||||
let mut io = pcm.io_i16().unwrap();
|
||||
|
||||
// Make sure we don't start the stream too early
|
||||
let hwp = pcm.hw_params_current().unwrap();
|
||||
let swp = pcm.sw_params_current().unwrap();
|
||||
swp.set_start_threshold(hwp.get_buffer_size().unwrap()).unwrap();
|
||||
pcm.sw_params(&swp).unwrap();
|
||||
|
||||
loop{
|
||||
let msg = stream.read(&mut buffer[..]).await?;
|
||||
println!("{:?}", str::from_utf8(&buffer[..msg]));
|
||||
io.write_all(&buffer[..]).unwrap()
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ use std::str;
|
|||
use std::ffi::CStr;
|
||||
use std::io::Read;
|
||||
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
let listener: TcpListener = TcpListener::bind("127.0.0.1:8080").await?;
|
||||
|
@ -51,8 +52,8 @@ async fn main() -> io::Result<()> {
|
|||
loop {
|
||||
let (mut socket, addr) = listener.accept().await?;
|
||||
io.read(&mut buffer).unwrap();
|
||||
let msg = socket.read(&mut buffer[..]).await?;
|
||||
println!("{}: {:?}",addr,str::from_utf8(&buffer[..msg]));
|
||||
|
||||
println!("{}",addr);
|
||||
socket.write_all(&buffer[..msg]).await?;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue