Mineserver
A rewrite of Minecraft 1.8.9 in C++ !
|
#include <network.h>
Public Member Functions | |
ClientSocket (socket_t client, char *addr) | |
Construct a new Client Socket object. | |
ClientSocket (int type) | |
Construct a new Client Socket object. | |
~ClientSocket ()=default | |
Destroy the Client Socket object. | |
bool | connect (const char *address, int port) const |
Connects to an address on a certain port . | |
bool | isValid () const |
Whether the connection is valid. | |
ssize_t | read (std::byte *buffer, size_t len) const |
Reads from the socket. | |
ssize_t | write (const std::byte *buffer, size_t len) const |
Writes to the socket. | |
void | close () const |
Closes the connection. | |
size_t | getAvailableBytes () const |
Get the number of available bytes. | |
socket_t | getHandle () const |
Get the Handle of the socket. | |
std::string | getAddress () const |
Get the Address of the client. | |
bool | isLocal () const |
Checks whether the connection is a local one. | |
Network POSIX Client.
Wrapper for cross-platform POSIX networking.
Construct a new Client Socket object.
Constructs a client socket, only used by the ServerSocket internally. You should use other constructers instead.
client | the client to attach on |
addr | the address on which the socket is connected |
ClientSocket::ClientSocket | ( | int | type | ) |
Construct a new Client Socket object.
Creates a new Socket client, to be able to connect to remote addresses manually.
type | the socket type, please use SOCK_STREAM |
void ClientSocket::close | ( | ) | const |
Closes the connection.
Must be run when you finish your work or else it will come at a cost of leaking memory !
Connects to an address
on a certain port
.
Keep in mind that if the ClientSocket was constructed by the ServerSocket, this function will fail !
address | the address to connect on |
port | the port to connect on |
|
inline |
Get the Address of the client.
size_t ClientSocket::getAvailableBytes | ( | ) | const |
Get the number of available bytes.
|
inline |
Get the Handle of the socket.
|
inline |
Checks whether the connection is a local one.
bool ClientSocket::isValid | ( | ) | const |
Whether the connection is valid.
Reads from the socket.
Everything is said.
buffer | the buffer to write into |
len | the maximum length to write |
Writes to the socket.
Everything is said.
buffer | the buffer to read from |
len | the maximum length to read |