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<()> {
|
||||
let addr = env::args()
|
||||
.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?;
|
||||
|
||||
|
|
|
@ -1,30 +1,49 @@
|
|||
use crate::chat::types::PackedMessage;
|
||||
use crate::fcpv2;
|
||||
use async_std::{
|
||||
io,
|
||||
net::{TcpListener, TcpStream},
|
||||
task,
|
||||
};
|
||||
use async_tungstenite::{accept_async, tungstenite::Message, WebSocketStream};
|
||||
use async_std::task;
|
||||
use futures::{SinkExt, StreamExt};
|
||||
use serde_derive::Deserialize;
|
||||
use std::env;
|
||||
use std::sync::mpsc::Sender;
|
||||
use tokio::{
|
||||
io::{self, AsyncReadExt, AsyncWriteExt},
|
||||
net::{TcpListener, TcpStream},
|
||||
};
|
||||
|
||||
type SP = Sender<PackedMessage>;
|
||||
|
||||
pub fn listen_server(server_sender: SP) -> io::Result<()> {
|
||||
task::block_on(connect_to_server(server_sender))
|
||||
#[tokio::main]
|
||||
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()
|
||||
.nth(1)
|
||||
.unwrap_or_else(|| "127.0.0.1:9481".to_string());
|
||||
|
||||
println!("Thats All?!");
|
||||
let listener = TcpStream::connect(&addr).await?;
|
||||
println!("Listened ");
|
||||
let stream = TcpStream::connect(&addr).await.expect("weeror here");
|
||||
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(())
|
||||
}
|
||||
|
@ -37,7 +56,7 @@ struct FrontMsg {
|
|||
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
|
||||
.peer_addr()
|
||||
.expect("connected streams should have a peer address");
|
||||
|
|
|
@ -4,7 +4,7 @@ mod encrypting;
|
|||
mod fcpv2;
|
||||
use async_std::io;
|
||||
use chat::front_conn::listen_client;
|
||||
//use chat::serv_conn::listen_server;
|
||||
use chat::serv_conn::listen_server;
|
||||
use chat::types::PackedMessage;
|
||||
|
||||
use async_std::task;
|
||||
|
@ -53,7 +53,7 @@ fn main() -> io::Result<()> {
|
|||
let cs = client_sender;
|
||||
let sr = server_receiver;
|
||||
|
||||
//thread::spawn(|| listen_server(cs));
|
||||
thread::spawn(|| listen_server(cs));
|
||||
println!("Multithreadding YAY!!! {}", sr.recv().unwrap().message);
|
||||
});
|
||||
let client_thread = thread::spawn(move || {
|
||||
|
@ -61,7 +61,7 @@ fn main() -> io::Result<()> {
|
|||
let cr = client_receiver;
|
||||
|
||||
thread::spawn(|| listen_client(ss));
|
||||
// println!("From Server Yaaay {}", cr.recv().unwrap().message);
|
||||
println!("From Server Yaaay {}", cr.recv().unwrap().message);
|
||||
});
|
||||
server_thread.join();
|
||||
client_thread.join();
|
||||
|
|
Loading…
Reference in a new issue