bettola/libbettola/include/bettola/network/socket.h
Ritchie Cunningham 6e935918a3 feat(server) Added client/server for online play
Note: This is fucking broken! it's too early in the morning. Fix
tomorrow.
2025-09-13 05:22:30 +01:00

38 lines
796 B
C++

#pragma once
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <string>
#include <cstdio>
namespace BettolaLib {
namespace Network {
class Socket {
public:
Socket(void);
~Socket(void);
bool create(void);
bool bind(unsigned short port);
bool listen(int backlog = 5);
Socket* accept(void); /* Return a new Socket for the accepted connection. */
bool connect(const std::string& ip_address, unsigned short port);
ssize_t send(const void* buffer, size_t length);
ssize_t recv(void* buffer, size_t length);
void close(void);
int get_sockfd(void) const { return _sockfd; }
bool is_valid(void) const { return _sockfd != -1; }
private:
int _sockfd;
struct sockaddr_in _address;
};
} /* namespace Network. */
} /* namespace BettolaLib. */