updates
This commit is contained in:
55
client.cpp
Normal file
55
client.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user