You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
#ifndef _SERVER
|
|
#define _SERVER
|
|
#include "includes/sock.hpp"
|
|
|
|
/* Server class - This class is used to create a TCP/UDP server.
|
|
It inherits from the 'Sock' class. */
|
|
|
|
class Server : public Sock {
|
|
|
|
private:
|
|
/* Address of the peer/client */
|
|
std::string peer_addr;
|
|
|
|
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 */
|
|
char* recvAll();
|
|
|
|
/* Non-blocking receive */
|
|
char* recvAllNB();
|
|
|
|
/* Return the address of the peer */
|
|
std::string get_peer_addr();
|
|
|
|
/* Return the type of socket */
|
|
int get_type() override;
|
|
};
|
|
#endif
|