fcp nodehello request works
This commit is contained in:
parent
dc87e678b8
commit
f55ed0700a
|
@ -19,7 +19,7 @@ pub fn listen_client(server_sender: SP) -> io::Result<()> {
|
||||||
async fn connect_to_client(server_sender: SP) -> io::Result<()> {
|
async fn connect_to_client(server_sender: SP) -> io::Result<()> {
|
||||||
let addr = env::args()
|
let addr = env::args()
|
||||||
.nth(1)
|
.nth(1)
|
||||||
.unwrap_or_else(|| "127.0.0.1:8989".to_string());
|
.unwrap_or_else(|| "127.0.0.1:5948".to_string());
|
||||||
|
|
||||||
let listener = TcpListener::bind(&addr).await?;
|
let listener = TcpListener::bind(&addr).await?;
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,49 @@
|
||||||
use crate::chat::types::PackedMessage;
|
use crate::chat::types::PackedMessage;
|
||||||
use crate::fcpv2;
|
use crate::fcpv2;
|
||||||
use async_std::{
|
use async_std::task;
|
||||||
io,
|
|
||||||
net::{TcpListener, TcpStream},
|
|
||||||
task,
|
|
||||||
};
|
|
||||||
use async_tungstenite::{accept_async, tungstenite::Message, WebSocketStream};
|
|
||||||
use futures::{SinkExt, StreamExt};
|
use futures::{SinkExt, StreamExt};
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
use tokio::{
|
||||||
|
io::{self, AsyncReadExt, AsyncWriteExt},
|
||||||
|
net::{TcpListener, TcpStream},
|
||||||
|
};
|
||||||
|
|
||||||
type SP = Sender<PackedMessage>;
|
type SP = Sender<PackedMessage>;
|
||||||
|
|
||||||
pub fn listen_server(server_sender: SP) -> io::Result<()> {
|
#[tokio::main]
|
||||||
task::block_on(connect_to_server(server_sender))
|
pub async fn listen_server(client_sender: SP) -> io::Result<()> {
|
||||||
|
task::block_on(connect_to_server(client_sender))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn connect_to_server(server_sender: SP) -> io::Result<()> {
|
async fn connect_to_server(client_sender: SP) -> io::Result<()> {
|
||||||
let addr = env::args()
|
let addr = env::args()
|
||||||
.nth(1)
|
.nth(1)
|
||||||
.unwrap_or_else(|| "127.0.0.1:9481".to_string());
|
.unwrap_or_else(|| "127.0.0.1:9481".to_string());
|
||||||
|
|
||||||
println!("Thats All?!");
|
println!("Thats All?!");
|
||||||
let listener = TcpStream::connect(&addr).await?;
|
let stream = TcpStream::connect(&addr).await.expect("weeror here");
|
||||||
println!("Listened ");
|
println!("stream created");
|
||||||
|
let (mut receiver, mut sender) = stream.into_split();
|
||||||
|
println!("FSFDSFD");
|
||||||
|
let _ = sender
|
||||||
|
.write(("ClientHello\nName=ggg\nExpectedVersion=2.0\nEndMessage\n\n").as_bytes())
|
||||||
|
.await?;
|
||||||
|
loop {
|
||||||
|
let mut buffer = [0; 512];
|
||||||
|
match receiver.read(&mut buffer).await {
|
||||||
|
Ok(s) => {
|
||||||
|
let received = String::from_utf8_lossy(&buffer[..]);
|
||||||
|
client_sender
|
||||||
|
.send(PackedMessage {
|
||||||
|
message: received.to_string(),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
Err(e) => println!("Error: {} ", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -37,7 +56,7 @@ struct FrontMsg {
|
||||||
time: String,
|
time: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn accept_server(stream: TcpStream, server_sender: SP) -> io::Result<()> {
|
async fn accept_server(stream: TcpStream, client_sender: SP) -> io::Result<()> {
|
||||||
let addr = stream
|
let addr = stream
|
||||||
.peer_addr()
|
.peer_addr()
|
||||||
.expect("connected streams should have a peer address");
|
.expect("connected streams should have a peer address");
|
||||||
|
|
|
@ -4,7 +4,7 @@ mod encrypting;
|
||||||
mod fcpv2;
|
mod fcpv2;
|
||||||
use async_std::io;
|
use async_std::io;
|
||||||
use chat::front_conn::listen_client;
|
use chat::front_conn::listen_client;
|
||||||
//use chat::serv_conn::listen_server;
|
use chat::serv_conn::listen_server;
|
||||||
use chat::types::PackedMessage;
|
use chat::types::PackedMessage;
|
||||||
|
|
||||||
use async_std::task;
|
use async_std::task;
|
||||||
|
@ -53,7 +53,7 @@ fn main() -> io::Result<()> {
|
||||||
let cs = client_sender;
|
let cs = client_sender;
|
||||||
let sr = server_receiver;
|
let sr = server_receiver;
|
||||||
|
|
||||||
//thread::spawn(|| listen_server(cs));
|
thread::spawn(|| listen_server(cs));
|
||||||
println!("Multithreadding YAY!!! {}", sr.recv().unwrap().message);
|
println!("Multithreadding YAY!!! {}", sr.recv().unwrap().message);
|
||||||
});
|
});
|
||||||
let client_thread = thread::spawn(move || {
|
let client_thread = thread::spawn(move || {
|
||||||
|
@ -61,7 +61,7 @@ fn main() -> io::Result<()> {
|
||||||
let cr = client_receiver;
|
let cr = client_receiver;
|
||||||
|
|
||||||
thread::spawn(|| listen_client(ss));
|
thread::spawn(|| listen_client(ss));
|
||||||
// println!("From Server Yaaay {}", cr.recv().unwrap().message);
|
println!("From Server Yaaay {}", cr.recv().unwrap().message);
|
||||||
});
|
});
|
||||||
server_thread.join();
|
server_thread.join();
|
||||||
client_thread.join();
|
client_thread.join();
|
||||||
|
|
Loading…
Reference in a new issue