XPMP2
X-Plane multiplayer library 2 - using instancing
|
Listens to TCP connections and opens a session socket upon connect. More...
#include <Network.h>
Public Member Functions | |
TCPConnection () | |
Default constructor is not doing anything. More... | |
void | Close () override |
also close session connection More... | |
void | CloseListenerOnly () |
only closes the listening socket, but not a connected session More... | |
void | listen (int numConnections=1) |
listen for incoming connections More... | |
bool | accept (bool bUnlisten=false) |
accept an incoming connections, optinally stop listening More... | |
bool | listenAccept (int numConnections=1) |
combines listening and accepting More... | |
bool | IsConnected () const |
Connected to a counterparty? More... | |
bool | send (const char *msg) override |
send messages on session connection More... | |
Public Member Functions inherited from XPMP2::SocketNetworking | |
SocketNetworking () | |
Default constructor is not doing anything. More... | |
virtual | ~SocketNetworking () |
Destructor makes sure the socket is closed. More... | |
virtual void | Open (const std::string &_addr, int _port, size_t _bufSize=512, unsigned _timeOut_ms=0, bool _bBroadcast=false) |
Creates a socket and binds it to the given local address. More... | |
virtual void | Connect (const std::string &_addr, int _port, size_t _bufSize, unsigned _timeOut_ms=0) |
Creates a socket and connects it to the given remote server. More... | |
bool | isOpen () const |
Is a socket open? More... | |
void | SetBufSize (size_t _bufSize) |
(Re)Sets the buffer size (or clears it if _bufSize==0 ) More... | |
SOCKET | getSocket () const |
the socket More... | |
int | getPort () const |
the port More... | |
std::string | getAddr () const |
the interface address More... | |
const char * | getBuf () const |
return the buffer More... | |
void | setBlocking (bool bBlock) |
Set blocking mode. More... | |
long | recv (std::string *_pFromAddr=nullptr, SockAddrTy *_pFromSockAddr=nullptr) |
Waits to receive a message, ensures zero-termination in the buffer. More... | |
long | timedRecv (int max_wait_ms, std::string *_pFromAddr=nullptr, SockAddrTy *_pFromSockAddr=nullptr) |
Waits to receive a message with timeout, ensures zero-termination in the buffer. More... | |
bool | broadcast (const char *msg) |
Sends a broadcast message. More... | |
Protected Member Functions | |
void | GetAddrHints (struct addrinfo &hints) override |
Subclass to tell which addresses to look for. More... | |
Protected Attributes | |
SOCKET | f_session_socket = INVALID_SOCKET |
session socket, ie. the socket opened when a counterparty connects More... | |
struct sockaddr_in | f_session_addr = {} |
address of the connecting counterparty More... | |
Protected Attributes inherited from XPMP2::SocketNetworking | |
SOCKET | f_socket = INVALID_SOCKET |
int | f_port = 0 |
std::string | f_addr |
char * | buf = NULL |
size_t | bufSize = 512 |
Additional Inherited Members | |
Static Public Member Functions inherited from XPMP2::SocketNetworking | |
static std::string | GetLastErr () |
Returns a human-readable text for the last error. More... | |
static std::string | GetAddrString (const SockAddrTy &sa, bool withPort=true) |
Convert addresses to string. More... | |
Listens to TCP connections and opens a session socket upon connect.
|
inline |
Default constructor is not doing anything.
bool XPMP2::TCPConnection::accept | ( | bool | bUnlisten = false | ) |
accept an incoming connections, optinally stop listening
|
overridevirtual |
also close session connection
Reimplemented from XPMP2::SocketNetworking.
void XPMP2::TCPConnection::CloseListenerOnly | ( | ) |
only closes the listening socket, but not a connected session
|
overrideprotectedvirtual |
Subclass to tell which addresses to look for.
Implements XPMP2::SocketNetworking.
|
inline |
Connected to a counterparty?
void XPMP2::TCPConnection::listen | ( | int | numConnections = 1 | ) |
listen for incoming connections
bool XPMP2::TCPConnection::listenAccept | ( | int | numConnections = 1 | ) |
combines listening and accepting
|
overridevirtual |
send messages on session connection
Reimplemented from XPMP2::SocketNetworking.
|
protected |
address of the connecting counterparty
|
protected |
session socket, ie. the socket opened when a counterparty connects