|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#include "easysock.hpp"
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#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) {
|
|
|
|
|