initial stub
This commit is contained in:
parent
d67fc3b2df
commit
6b97847882
1622
rustybot/Cargo.lock
generated
Normal file
1622
rustybot/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
13
rustybot/Cargo.toml
Normal file
13
rustybot/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[package]
|
||||||
|
name = "rustybot"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Giulio De Pasquale <depasquale@giugl.io>"]
|
||||||
|
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" }
|
||||||
|
tokio = { version = "0.3", features=["full"]}
|
||||||
|
tokio-tungstenite = "*"
|
||||||
|
futures-util = { version = "0.3", default-features = false, features = ["async-await", "sink", "std"] }
|
35
rustybot/src/main.rs
Normal file
35
rustybot/src/main.rs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
|
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(())
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
@ -10,4 +10,6 @@ socket.on("connect", function () {
|
|||||||
console.log("Connected!")
|
console.log("Connected!")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const ws = new WebSocket('ws://localhost:8080');
|
||||||
|
|
||||||
ReactDOM.render(<App/>, document.getElementById("root"));
|
ReactDOM.render(<App/>, document.getElementById("root"));
|
||||||
|
Loading…
Reference in New Issue
Block a user