From 9f6fba4fc1175df26fa68f0d8e637b42d76df64d Mon Sep 17 00:00:00 2001 From: Trance-0 Date: Mon, 2 Feb 2026 00:00:40 -0600 Subject: [PATCH] updates --- .env | 4 ++++ client.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 48 +++++++++++++++++++++++++++++++++++++++ server | Bin 0 -> 16752 bytes server.cpp | 36 +++++++++++++++++++++++++++++ 5 files changed, 143 insertions(+) create mode 100644 .env create mode 100644 client.cpp create mode 100644 docker-compose.yml create mode 100755 server create mode 100644 server.cpp diff --git a/.env b/.env new file mode 100644 index 0000000..c7ab229 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +SERVER_IP=172.30.0.39 +SERVER_PORT=3030 +CLIENT_IP=172.30.0.40 +NET_SUBNET= \ No newline at end of file diff --git a/client.cpp b/client.cpp new file mode 100644 index 0000000..e2855e2 --- /dev/null +++ b/client.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include + +#include +#include + +void load_env(const std::string& path) { + std::ifstream f(path); + std::string line; + while (std::getline(f, line)) { + if (line.empty() || line[0] == '#') continue; + auto pos = line.find('='); + if (pos == std::string::npos) continue; + + std::string key = line.substr(0, pos); + std::string val = line.substr(pos + 1); + +#ifdef _WIN32 + _putenv_s(key.c_str(), val.c_str()); +#else + setenv(key.c_str(), val.c_str(), 1); +#endif + } +} +namespace std {} + +int main(void){ + load_env(".env"); + // Declare variables + const char *server_ip = std::getenv("SERVER_IP"); + const int server_port = std::atoi(std::getenv("SERVER_PORT")); + char client_message[1024]; + char server_message[1024]; + // Create socket: + + // Send connection request to server, be sure to set por tand IP the same as server-side + + // Get input from the user: + printf("Enter message sent to the server: "); + // fgets(client_message); + + // Send the message to server: + + // Receive the server's response: + + + printf("Server's response: %s\n", server_message); + + // Close the socket + + return 0; +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2683ba5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,48 @@ +services: + server: + image: gcc:13 + working_dir: /app + volumes: + - ./:/app:rw + env_file: + - .env + networks: + net-hw1: + ipv4_address: ${SERVER_IP} + command: > + bash -lc " + set -euo pipefail; + g++ -std=c++17 -O2 -Wall -Wextra -pedantic /app/server.cpp -o /tmp/server; + echo '[server] IP='$(hostname -i)' SERVER_IP='${SERVER_IP}' SERVER_PORT='${APP_PORT}; + exec /tmp/server + " + + client: + image: gcc:13 + working_dir: /app + volumes: + - ./:/app:rw + env_file: + - .env + networks: + net-hw1: + ipv4_address: ${CLIENT_IP} + depends_on: + - server + stdin_open: true + tty: true + command: > + bash -lc " + set -euo pipefail; + g++ -std=c++17 -O2 -Wall -Wextra -pedantic /app/client.cpp -o /tmp/client; + echo '[client] IP='$(hostname -i)' CLIENT_IP='${CLIENT_IP}' SERVER_IP='${SERVER_IP}' APP_PORT='${APP_PORT}; + exec /tmp/client + " + +networks: + net-hw1: + name: net-hw1 + driver: bridge + ipam: + config: + - subnet: ${NET_SUBNET} diff --git a/server b/server new file mode 100755 index 0000000000000000000000000000000000000000..98777c0ec7a7d32b281143995d5ad60d10877dfc GIT binary patch literal 16752 zcmeHOZEPGz8J_dS$)!!smyl35g?ig2QbO^?c3js93cd4J*2qarYWIUS-JI{%_R;g5 zx!Y^)3YC`-STN-p5+%FE(p^*`B&I?=2iet< zK=EFBR@IX!%PZw+WQ?TAdxf4R1tg|UJF3cbqZEtj?QXhHl{cy=+Yw84Gsvi7!4~dqczP&$izB#xr-n{`wQ|vkxkhbSRNM zcM0MtzYG`Y*w6n6ayCZvl=;&!qKl=^K%i9-UJYz@6`bC;YB)W0HT(hK8ZK`-2tf0K z;BUfpV-;K=-bo5?n=p)ml}O%iBuDQzh7;+G7|*A()-dqoM8X(OXA_z9Lnc@F)X zj3v@pv7@iIqtj@KwnT5KQe2l_POaCaur=xQN@~4+^{o8<^Lw{%l`S}`-fzY=g@`0gp@q5UnXjma>{!SD6(gHFEr_r0Z4_vxi~ z^aH<{>mTTws%^s*Q=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tx8j-nx@j_19L;HMsRZEO`8IB9ANm{i;82R`@C4q#yCzxNmdp$hoursQlwnw7Mv{(Y6mTRXl`}>%xuHbHNLjgj!AKM* zL^3xvo-y%%!<5+)ALfTrbAmHV6W z(d76zG<){McXk`yySfaV332PDgwb{PuK3R0PParJLji z*xl1}d-s4b5bx;gCa?1FO0rOtwf^8kDrPESC1Bz{788r{d6!moLS`PJ6EF+T$9To$ z)js+HUH3T{BUQ*5qxi=?ossF?4J~{EFp32ek3U~?3L^NSLP5Ear*I4dM{GEFboQp| zfg1N=9(UD5v@khlC5Aw)yiG?rhm$~Neq2PeIm?WWWQ)=9d~V##TaylGsF=pNt#nF3 z@s8d`D={LZ`e>psDx#^$EQ+wHmA54inE66Fmvu1)WO*}_AOn>f&sZWVpFE0ebR-9s zG6gd!qLw)Umii&IbF$f@=BVm4BPWMhv^Jtl&FprXSV0{ zMj9ABGTZZflqs*1pdu6baHh|Jp*0BG^SqTQPg}VDtjF|W*wdPZd7j@gZBm7K>(6zV zLWW|>_B;<}I-?Z1eDCvrL)mvIJzlpl~% z?3i--%B$DCc*bMT^K_ +#include +#include +#include +#include + +int main(void){ + + // Declare variables + const char *server_ip = "127.0.0.1"; + const int server_port = 8080; + char client_message[1024]; + char server_message[1024]; + // Create socket + + + // Bind to the set port and IP + printf("Done with binding with IP: %s, Port: %d\n", server_ip, server_port); + + // Listen for clients: + const char *client_ip = "127.0.0.1"; + const int client_port = 12345; + + // Accept an incoming connection + printf("Client connected at IP: %s and port: %i\n", client_ip, client_port); + + // Receive client's message + printf("Msg from client: %s\n", client_message); + + // Respond to client + strcpy(server_message, "Hello from server"); + + // Close the socket + + return 0; +} \ No newline at end of file