libnick 2025.1.0
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
1#ifndef SOCKET_H
2#define SOCKET_H
3
4#include <memory>
5#include <string>
6#ifdef _WIN32
7#include <Winsock2.h>
8#endif
9#include "addressfamily.h"
10#include "socketpurpose.h"
11#include "sockettype.h"
12
13namespace Nickvision::Network
14{
18 class Socket
19 {
20 public:
33 Socket(SocketPurpose purpose, SocketType type, AddressFamily family, const std::string& address, int port);
45 bool connect();
52 bool disconnect();
60 std::string receiveMessage() const;
69 bool sendMessage(const std::string& message) const;
70
71 private:
72 SocketPurpose m_purpose;
73 SocketType m_type;
74 AddressFamily m_family;
75 std::string m_address;
76 int m_port;
77#ifdef _WIN32
78 SOCKET m_socket;
79 SOCKET m_child;
80 HANDLE m_pipe;
81#else
82 int m_socket;
83 int m_child;
84#endif
85 };
86}
87
88#endif //SOCKET_H
A network socket (an endpoint for communication).
Definition socket.h:19
bool connect()
Establishes a connection.
~Socket()
Destructs a Socket.
Socket(SocketPurpose purpose, SocketType type, AddressFamily family, const std::string &address, int port)
Constructs a Socket.
std::string receiveMessage() const
Receives a message.
bool sendMessage(const std::string &message) const
Sends a message.
bool disconnect()
Closes a connection.
Definition addressfamily.h:11
SocketType
Type of sockets.
Definition sockettype.h:16
SocketPurpose
Purposes of sockets.
Definition socketpurpose.h:10
AddressFamily
Type of address that can be used by a socket.
Definition addressfamily.h:16