Completely rewrote Server class, and split the class into header and implementation
This commit is contained in:
@@ -1,30 +1,33 @@
|
||||
#ifndef _SERVER
|
||||
#define _SERVER
|
||||
#include "includes/sock.hpp"
|
||||
#include "includes/exception_consts.hpp"
|
||||
|
||||
/*
|
||||
Server class - Inherits from 'Sock' class - Defines a TCP/UDP server.
|
||||
*/
|
||||
/* Server class - This class is used to create a TCP/UDP server.
|
||||
It inherits from the 'Sock' class. */
|
||||
|
||||
class Server : public Sock {
|
||||
|
||||
private:
|
||||
void create_socket() {
|
||||
Sock::create_socket();
|
||||
this->sock_fd = create_local(this->ip_ver, this->protocol, this->address.data(), this->port, dest);
|
||||
if (sock_fd < 0) {
|
||||
if (sock_fd * -1 == ECONNREFUSED) {
|
||||
throw EXCEPT_CONNREFUSED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
/* Constructors */
|
||||
Server() {}
|
||||
|
||||
Server(int ip_ver, char protocol, const char* address, int port) : Sock(ip_ver, protocol, address, port) {}
|
||||
|
||||
/* Destructor */
|
||||
~Server();
|
||||
|
||||
/* Method to create socket - overrides (i.e. extends) method from parent class */
|
||||
void create_socket() override;
|
||||
|
||||
/* FOR TCP ONLY - Wait for a peer to connect to this socket, and store the result in 'other_socket' */
|
||||
void wait_for_peer();
|
||||
|
||||
/* FOR TCP - Send data to the peer socket
|
||||
FOR UDP - Send data to the client, from which data was received.
|
||||
FOR UDP, this function MUST be called after recvAll() */
|
||||
void sendAll(std::string to_send);
|
||||
|
||||
/* Receive data from peer socket */
|
||||
std::string recvAll();
|
||||
};
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user