22 lines
672 B
C++
22 lines
672 B
C++
#pragma once
|
|
#include "../modernize/sockets.h"
|
|
|
|
class networked
|
|
{
|
|
protected:
|
|
SOCKET socket;
|
|
public:
|
|
explicit networked(SOCKET existing)
|
|
{
|
|
socket = existing;
|
|
}
|
|
auto disconnect() -> void
|
|
{
|
|
if (!is_valid()) return; //socket is closed.
|
|
net::closesocket(socket);
|
|
socket = INVALID_SOCKET;
|
|
}
|
|
[[nodiscard]] auto receive_message() const -> std::string { if (!is_valid()) return ""; return net::recv(socket); }
|
|
auto send_message(const std::string& message) const -> void { if (!is_valid()) return; net::send(socket, message);}
|
|
[[nodiscard]] auto is_valid() const -> bool { return socket != INVALID_SOCKET; }
|
|
}; |