-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from jabibamman/feat/server-client-connection
Feat(Server) - client/server connexion + write message
- Loading branch information
Showing
8 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,32 @@ | ||
use server::services::{connect::connect, write::write}; | ||
|
||
/// Connect to the server and send a message | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `host` - Hostname | ||
/// * `port` - Port | ||
/// | ||
/// # Return | ||
/// | ||
/// * `Result<TcpStream, std::io::Error>` - TcpStream | ||
/// | ||
/// # Example | ||
/// | ||
/// ``` | ||
/// use client::client::connect_server; | ||
/// | ||
/// let stream = connect_server("localhost", "8080"); | ||
/// ``` | ||
/// | ||
/// # Panic | ||
/// | ||
/// * `std::io::Error` - If the connection failed | ||
/// | ||
pub fn connect_server(host: &str, port: &str) -> std::io::Result<std::net::TcpStream> { | ||
let stream = connect(format!("{}:{}", host, port))?; | ||
|
||
write(stream, "Hello World !")?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod handler; | ||
pub mod image; | ||
pub mod services; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use std::io::Result; | ||
use std::net::TcpStream; | ||
|
||
/// Connect to a server | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `address` - Address | ||
/// | ||
/// # Return | ||
/// | ||
/// * `Result<TcpStream, std::io::Error>` - TcpStream | ||
pub fn connect(address: &str) -> Result<TcpStream> { | ||
let stream = TcpStream::connect(address)?; | ||
|
||
Ok(stream) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod connect; | ||
pub mod write; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::io::Result; | ||
use std::io::Write; | ||
use std::net::TcpStream; | ||
|
||
/// Write a string to a stream | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `stream` - TcpStream | ||
/// * `message` - String | ||
/// | ||
/// # Return | ||
/// | ||
/// * `Result<TcpStream, std::io::Error>` - TcpStream | ||
pub fn write(mut stream: TcpStream, message: &str) -> Result<TcpStream> { | ||
stream.write(format!("${}", message).as_bytes())?; | ||
|
||
Ok(stream) | ||
} |