removed socket_send_tx and replace with socket.send
This commit is contained in:
parent
35bc3df300
commit
c0033e89fc
3 changed files with 6 additions and 11 deletions
|
@ -18,14 +18,13 @@ fn main() {
|
||||||
|
|
||||||
let socket_listener = Socket::make_listener(SERVER_ADDRESS);
|
let socket_listener = Socket::make_listener(SERVER_ADDRESS);
|
||||||
let (from_socket_tx, from_socket_rx) = unbounded::<String>();
|
let (from_socket_tx, from_socket_rx) = unbounded::<String>();
|
||||||
let (to_socket_tx, to_socket_rx) = unbounded::<String>();
|
let mut socket = Socket::handle_connections(socket_listener, from_socket_tx);
|
||||||
let mut socket = Socket::handle_connections(socket_listener, from_socket_tx, to_socket_rx);
|
|
||||||
|
|
||||||
let (control_c_flag_tx, control_c_called_flag_rx) = sync_flag::new_syncflag(false);
|
let (control_c_flag_tx, control_c_called_flag_rx) = sync_flag::new_syncflag(false);
|
||||||
|
|
||||||
setup_control_c(control_c_flag_tx);
|
setup_control_c(control_c_flag_tx);
|
||||||
let _outgoing = std::net::TcpStream::connect(SERVER_ADDRESS).unwrap();
|
let _outgoing = std::net::TcpStream::connect(SERVER_ADDRESS).unwrap();
|
||||||
to_socket_tx.send("this is a message".to_string()).unwrap();
|
socket.send("this is a message".to_string());
|
||||||
//until control_c is caught, check the queue of incoming
|
//until control_c is caught, check the queue of incoming
|
||||||
//requests from the socket handler.
|
//requests from the socket handler.
|
||||||
while !control_c_called_flag_rx.get() {
|
while !control_c_called_flag_rx.get() {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use std::ops::Add;
|
|
||||||
|
|
||||||
use super::enums::{SubScenes, Scenes, SlideChange};
|
use super::enums::{SubScenes, Scenes, SlideChange};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
|
@ -32,9 +32,8 @@ fn panic_no_listener() {
|
||||||
fn can_handle_messages() {
|
fn can_handle_messages() {
|
||||||
let listener = Socket::make_listener("localhost:5004");
|
let listener = Socket::make_listener("localhost:5004");
|
||||||
let (tx_1, rx_1) = unbounded::<String>();
|
let (tx_1, rx_1) = unbounded::<String>();
|
||||||
let (_stream_tx, stream_rx) = unbounded::<String>();
|
|
||||||
|
|
||||||
let mut socket = Socket::handle_connections(listener, tx_1, stream_rx);
|
let mut socket = Socket::handle_connections(listener, tx_1);
|
||||||
|
|
||||||
let join_handle = std::thread::spawn(move || {
|
let join_handle = std::thread::spawn(move || {
|
||||||
let mut outgoing = std::net::TcpStream::connect("localhost:5004").unwrap();
|
let mut outgoing = std::net::TcpStream::connect("localhost:5004").unwrap();
|
||||||
|
@ -54,9 +53,8 @@ fn can_handle_messages() {
|
||||||
fn can_handle_delayed_messages() {
|
fn can_handle_delayed_messages() {
|
||||||
let listener = Socket::make_listener("localhost:5005");
|
let listener = Socket::make_listener("localhost:5005");
|
||||||
let (tx_1, rx_1) = unbounded::<String>();
|
let (tx_1, rx_1) = unbounded::<String>();
|
||||||
let (_stream_tx, stream_rx) = unbounded::<String>();
|
|
||||||
|
|
||||||
let mut socket = Socket::handle_connections(listener, tx_1, stream_rx);
|
let mut socket = Socket::handle_connections(listener, tx_1);
|
||||||
|
|
||||||
let mut outgoing = std::net::TcpStream::connect("localhost:5005").unwrap();
|
let mut outgoing = std::net::TcpStream::connect("localhost:5005").unwrap();
|
||||||
outgoing.write("this is a test1\n".as_bytes()).unwrap();
|
outgoing.write("this is a test1\n".as_bytes()).unwrap();
|
||||||
|
@ -80,9 +78,8 @@ fn can_handle_delayed_messages() {
|
||||||
fn can_send_and_receive_on_stream() {
|
fn can_send_and_receive_on_stream() {
|
||||||
let listener = Socket::make_listener("localhost:5006");
|
let listener = Socket::make_listener("localhost:5006");
|
||||||
let (tx_1, rx_1) = unbounded::<String>();
|
let (tx_1, rx_1) = unbounded::<String>();
|
||||||
let (stream_tx, stream_rx) = unbounded::<String>();
|
|
||||||
|
|
||||||
let mut socket = Socket::handle_connections(listener, tx_1, stream_rx);
|
let mut socket = Socket::handle_connections(listener, tx_1);
|
||||||
|
|
||||||
let mut outgoing = std::net::TcpStream::connect("localhost:5006").unwrap();
|
let mut outgoing = std::net::TcpStream::connect("localhost:5006").unwrap();
|
||||||
outgoing.set_read_timeout(Some(Duration::from_millis(1000))).expect("couln't set timout");
|
outgoing.set_read_timeout(Some(Duration::from_millis(1000))).expect("couln't set timout");
|
||||||
|
@ -92,7 +89,7 @@ fn can_send_and_receive_on_stream() {
|
||||||
thread::sleep(Duration::from_millis(250));
|
thread::sleep(Duration::from_millis(250));
|
||||||
assert_eq!(rx_1.try_recv().unwrap(), "such a test!\n");
|
assert_eq!(rx_1.try_recv().unwrap(), "such a test!\n");
|
||||||
|
|
||||||
stream_tx.send("this is another test!".to_string()).unwrap();
|
socket.send("this is another test!".to_string());
|
||||||
thread::sleep(Duration::from_millis(250));
|
thread::sleep(Duration::from_millis(250));
|
||||||
|
|
||||||
let mut buffer = [0; 256];
|
let mut buffer = [0; 256];
|
||||||
|
|
Loading…
Reference in a new issue