Files
netpong/includes/server.hpp
Rockingcool 0058e7e411 Removed ip_ver parameter
I removed this because I realized I could just check the IP version inside
the constructor. The Sock constructor now checks the address passed to it.
Like before, if the address is neither v4 nor v6, an exception is thrown.
Since the Server and Client constructors call the Sock constructor, no change
was required in these files, except passing the right number of parameters.
2024-03-10 21:53:06 -05:00

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(char protocol, const char* address, int port) : Sock(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