Rust
Rust
SSL Client Example
See more Socket/SSL/TLS Examples
Demonstrates how to connect to an SSL server, send a simple message, receive a simple response, and disconnect.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let socket = chilkat::Socket::new();
let ssl = true;
let max_wait_millisec = 20000;
// The SSL server hostname may be an IP address, a domain name,
// or "localhost". You'll need to change this:
let ssl_server_host = "123.123.88.88".to_string();
let ssl_server_port = 8123;
// Connect to the SSL server:
if socket.connect(&ssl_server_host, ssl_server_port, ssl, max_wait_millisec).is_err() {
println!("{}", socket.last_error_text());
return;
}
// Set maximum timeouts for reading an writing (in millisec)
socket.set_max_read_idle_ms(20000);
socket.set_max_send_idle_ms(20000);
// Send a "Hello Server! -EOM-" message:
if socket.send_string("Hello Server! -EOM-").is_err() {
println!("{}", socket.last_error_text());
return;
}
// The server (in this example) is going to send a "Hello Client! -EOM-"
// message. Read it:
let Ok(received_msg) = socket.receive_until_match("-EOM-") else {
println!("{}", socket.last_error_text());
return;
};
// Close the connection with the server
// Wait a max of 20 seconds (20000 millsec)
let _ = socket.close(20000).is_ok();
println!("{}", received_msg);