Mineserver
A rewrite of Minecraft 1.8.9 in C++ !
Loading...
Searching...
No Matches
ServerSocket Class Reference

Network POSIX Server. More...

#include <network.h>

Public Member Functions

 ServerSocket ()
 Construct a new empty Server Socket object.
 
 ServerSocket (int type)
 Construct a new Server Socket object.
 
 ~ServerSocket ()=default
 Destroy the Server Socket object.
 
bool bind (const char *address, int port) const
 Binds the server to port / address.
 
void start (unsigned int backlog) const
 Starts the server.
 
ClientSocket accept () const
 Accepts a new client.
 
void close () const
 Closes the connection.
 

Static Public Member Functions

static bool init ()
 Inits the POSIX API.
 
static bool cleanup ()
 Cleansup the POSIX API.
 

Detailed Description

Network POSIX Server.

Wrapper for cross-platform POSIX networking.

Constructor & Destructor Documentation

◆ ServerSocket() [1/2]

ServerSocket::ServerSocket ( )
default

Construct a new empty Server Socket object.

Only used for late initialization, any call on an object initialized that way will fail.

◆ ServerSocket() [2/2]

ServerSocket::ServerSocket ( int type)

Construct a new Server Socket object.

Creates a server using the POSIX api.

Parameters
typethe socket type, please use SOCK_STREAM

Member Function Documentation

◆ accept()

ClientSocket ServerSocket::accept ( ) const

Accepts a new client.

Accepts asynchronously a new client, and gives back a wrapper for the client socket when the client is connected.

Returns
ClientSocket

◆ bind()

bool ServerSocket::bind ( const char * address,
int port ) const

Binds the server to port / address.

Binds the server to a specific address and port to listen on.

Parameters
addressthe address to bind on
portthe port to bind on
Returns
true binding was successful
false something went wrong

◆ cleanup()

bool ServerSocket::cleanup ( )
static

Cleansup the POSIX API.

Akin to ServerSocket::init(), we need also to cleanup windows mess ! Thanks again windows ! It will never fail on a Linux Machine.

Returns
true API was cleaned up correctly
false something went wrong

◆ close()

void ServerSocket::close ( ) const

Closes the connection.

Manually closes the connection, should be always ran when you finished your stuff.

◆ init()

bool ServerSocket::init ( )
static

Inits the POSIX API.

Because windows is not capable of making correct APIs, we need to initialize it, in the case we are running this code on a windows machine... Thanks windows ! It will never fail on a Linux Machine.

Returns
true API was loaded correctly
false something went wrong

◆ start()

void ServerSocket::start ( unsigned int backlog) const

Starts the server.

Starts listening for incoming connections, with a max "acceptance" of incoming connections of backlog

Parameters
backlogthe max incoming connections

The documentation for this class was generated from the following files: