diff --git a/includes/client.hpp b/includes/client.hpp index 4607381..80062e0 100644 --- a/includes/client.hpp +++ b/includes/client.hpp @@ -1,6 +1,7 @@ #include "easysock.hpp" #include - +#include +#include "exception_consts.hpp" /* Client class - Defines a TCP/UDP client. - The constructor takes in a **remote** address and port, and connects the client to that address/port. @@ -17,9 +18,16 @@ private: void create_socket() { struct sockaddr* dest = (struct sockaddr *)malloc(sizeof(struct sockaddr)); this->sock_fd = create_remote(this->ip_ver, this->protocol, this->address.data(), this->port, dest); + if (sock_fd < 0) { + if (sock_fd * -1 == ECONNREFUSED) { + throw EXCEPT_CONNREFUSED; + } + } } public: + Client() {} + Client(int ip_ver, char protocol, const char* address, int port) { /* Error checking */ if (ip_ver != 4 && ip_ver != 6) { @@ -36,7 +44,11 @@ public: this->protocol = protocol; this->port = port; this->address = std::string(address); - create_socket(); + try { + create_socket(); + } catch (int e) { + throw; + } } void sendAll(std::string to_send) { diff --git a/includes/server.hpp b/includes/server.hpp index a70537a..6f933ca 100644 --- a/includes/server.hpp +++ b/includes/server.hpp @@ -20,6 +20,8 @@ private: } public: + Server() {} + Server(int ip_ver, char protocol, int port) { /* Error checking */ if (ip_ver != 4 && ip_ver != 6) {