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.
38 lines
944 B
C++
38 lines
944 B
C++
#ifndef _SOCK_CLASS
|
|
#define _SOCK_CLASS
|
|
|
|
#include <iostream>
|
|
#include <sys/socket.h>
|
|
|
|
class Sock {
|
|
/* Define a parent class of client and server, that can be used in main.cpp, instead of defining a client and server. This will allow me to create a struct for Mode, that can store either a client or a server, depending on what mode the game is in. */
|
|
protected:
|
|
int ip_ver;
|
|
char protocol;
|
|
int port;
|
|
int sock_fd;
|
|
std::string address;
|
|
struct sockaddr* dest;
|
|
|
|
void create_socket();
|
|
|
|
|
|
public:
|
|
/* Default constructor */
|
|
Sock() {}
|
|
|
|
/* Regular constructor - defined in sock.cpp */
|
|
Sock(int ip_ver, char protocol, const char* address, int port);
|
|
|
|
/* Method to send data in 'to_send' to the destination - defined in sock.cpp */
|
|
void sendAll(std::string to_send);
|
|
|
|
/* Method to receive data sent to socket - defined in sock.cpp */
|
|
std::string recvAll();
|
|
|
|
/* Returns socket identifier - defined in sock.cpp */
|
|
int getSockFD();
|
|
};
|
|
|
|
#endif
|