Skip to content

Commit

Permalink
Merge pull request #463 from nworbnhoj/main
Browse files Browse the repository at this point in the history
make net ws more robust to test websocket server connection failure
  • Loading branch information
bunnie authored Dec 14, 2023
2 parents fe2eb73 + a111f1d commit b673510
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions services/shellchat/src/cmds/net_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,22 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
#[cfg(feature = "websocket")]
"ws" => {
if self.ws.is_none() {
let (socket, response) =
tungstenite::connect(url::Url::parse("wss://awake.noskills.club/ws").unwrap()).expect("Can't connect");

log::info!("Connected to the server");
log::info!("Response HTTP code: {}", response.status());
log::info!("Response contains the following headers:");
for (ref header, _value) in response.headers() {
log::info!("* {}", header);
let url = url::Url::parse("wss://awake.noskills.club/ws").expect("Can't parse");
match tungstenite::connect(url) {
Ok((socket, response)) => {
log::info!("Connected to the server");
log::info!("Response HTTP code: {}", response.status());
log::info!("Response contains the following headers:");
for (ref header, _value) in response.headers() {
log::info!("* {}", header);
}
self.ws = Some(socket);
}
Err(e) => {
log::warn!("failed to connect to ws server: {e}");
write!(ret, "failed to connect to ws server: {e}").ok();
}
}
self.ws = Some(socket);
}
let mut err = false;
if let Some(socket) = &mut self.ws {
Expand Down

0 comments on commit b673510

Please sign in to comment.