Skip to content

Commit

Permalink
OmpasGobotSim: handle panic in tcp
Browse files Browse the repository at this point in the history
  • Loading branch information
Yirmandias committed Jun 14, 2023
1 parent 5ff5d9e commit 5cab6e0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ompas-gobot-sim/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::convert::TryFrom;
use std::convert::TryInto;
use std::fmt::{Display, Formatter};
use std::net::SocketAddr;
use std::process::exit;
use tokio::io::{self, AsyncReadExt, AsyncWriteExt, BufReader, ReadHalf, WriteHalf};
use tokio::net::TcpStream;
use tokio::sync::mpsc::Receiver;
Expand All @@ -36,7 +37,13 @@ pub async fn task_tcp_connection(
command_response_sender: broadcast::Sender<CommandResponse>,
state_update_sender: broadcast::Sender<PlatformUpdate>,
) {
let stream = TcpStream::connect(socket_addr).await.unwrap();
let stream = match TcpStream::connect(socket_addr).await {
Ok(s) => s,
Err(e) => {
eprintln!("Error opening tcp connection with gobot-sim : {e:?}");
exit(0);
}
};

// splits the tcp connection into a read and write stream.
let (rd, wr) = io::split(stream);
Expand Down

0 comments on commit 5cab6e0

Please sign in to comment.