stuff
This commit is contained in:
parent
6b97847882
commit
2705e393df
@ -7,7 +7,7 @@ edition = "2018"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bitfinex = { path= "/home/giulio/gitstuff/bitfinex-rs" }
|
||||
bitfinex = { path= "/home/giulio/dev/bitfinex-rs" }
|
||||
tokio = { version = "0.3", features=["full"]}
|
||||
tokio-tungstenite = "*"
|
||||
futures-util = { version = "0.3", default-features = false, features = ["async-await", "sink", "std"] }
|
@ -1,35 +1,12 @@
|
||||
use std::env;
|
||||
use std::net::SocketAddr;
|
||||
mod ticker;
|
||||
mod positions;
|
||||
mod events;
|
||||
mod pairs;
|
||||
|
||||
use futures_util::StreamExt;
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
|
||||
pub type BoxError = Box<dyn std::error::Error + Send + Sync>;
|
||||
|
||||
async fn accept_connection(stream: TcpStream, addr: SocketAddr) -> Result<(), BoxError> {
|
||||
println!("Peer address: {}", addr);
|
||||
|
||||
|
||||
let ws_stream = tokio_tungstenite::accept_async(stream)
|
||||
.await
|
||||
.err(format!("Error during WS handshake.").into());
|
||||
|
||||
println!("New WebSocket connection: {}", addr);
|
||||
|
||||
let (write, read) = ws_stream.split();
|
||||
read.forward(write).await.expect("Failed to forward message")
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), BoxError> {
|
||||
// Create the event loop and TCP listener we'll accept connections on.
|
||||
let addr = env::args().nth(1).unwrap_or_else(|| "127.0.0.1:8080".to_string());
|
||||
let try_socket = TcpListener::bind(&addr).await;
|
||||
let mut listener = try_socket.expect("Failed to bind");
|
||||
|
||||
while let Ok((stream, addr)) = listener.accept().await {
|
||||
tokio::spawn(accept_connection(stream, addr));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user