XPMP2
X-Plane multiplayer library 2 - using instancing
XPMP2::TCPConnection Class Reference

Listens to TCP connections and opens a session socket upon connect. More...

#include <Network.h>

+ Inheritance diagram for XPMP2::TCPConnection:

Public Member Functions

 TCPConnection ()
 Default constructor is not doing anything.
 
void Close () override
 also close session connection
 
void CloseListenerOnly ()
 only closes the listening socket, but not a connected session
 
void listen (int numConnections=1)
 listen for incoming connections
 
bool accept (bool bUnlisten=false)
 accept an incoming connections, optinally stop listening
 
bool listenAccept (int numConnections=1)
 combines listening and accepting
 
bool IsConnected () const
 Connected to a counterparty?
 
bool send (const char *msg) override
 send messages on session connection
 
- Public Member Functions inherited from XPMP2::SocketNetworking
 SocketNetworking ()
 Default constructor is not doing anything.
 
virtual ~SocketNetworking ()
 Destructor makes sure the socket is closed.
 
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.
 
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.
 
bool isOpen () const
 Is a socket open?
 
void SetBufSize (size_t _bufSize)
 (Re)Sets the buffer size (or clears it if _bufSize==0)
 
SOCKET getSocket () const
 the socket
 
int getPort () const
 the port
 
std::string getAddr () const
 the interface address
 
const char * getBuf () const
 return the buffer
 
void setBlocking (bool bBlock)
 Set blocking mode.
 
long recv (std::string *_pFromAddr=nullptr, SockAddrTy *_pFromSockAddr=nullptr)
 Waits to receive a message, ensures zero-termination in the buffer.
 
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.
 
bool broadcast (const char *msg)
 Sends a broadcast message.
 

Protected Member Functions

void GetAddrHints (struct addrinfo &hints) override
 Subclass to tell which addresses to look for.
 
- Protected Member Functions inherited from XPMP2::SocketNetworking

Protected Attributes

SOCKET f_session_socket = INVALID_SOCKET
 session socket, ie. the socket opened when a counterparty connects
 
struct sockaddr_in f_session_addr = {}
 address of the connecting counterparty
 
- 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.
 
static std::string GetAddrString (const SockAddrTy &sa, bool withPort=true)
 Convert addresses to string.
 

Detailed Description

Listens to TCP connections and opens a session socket upon connect.

Constructor & Destructor Documentation

◆ TCPConnection()

XPMP2::TCPConnection::TCPConnection ( )
inline

Default constructor is not doing anything.

Member Function Documentation

◆ accept()

bool XPMP2::TCPConnection::accept ( bool bUnlisten = false)

accept an incoming connections, optinally stop listening

◆ Close()

void XPMP2::TCPConnection::Close ( )
overridevirtual

also close session connection

Reimplemented from XPMP2::SocketNetworking.

◆ CloseListenerOnly()

void XPMP2::TCPConnection::CloseListenerOnly ( )

only closes the listening socket, but not a connected session

◆ GetAddrHints()

void XPMP2::TCPConnection::GetAddrHints ( struct addrinfo & hints)
overrideprotectedvirtual

Subclass to tell which addresses to look for.

Implements XPMP2::SocketNetworking.

◆ IsConnected()

bool XPMP2::TCPConnection::IsConnected ( ) const
inline

Connected to a counterparty?

◆ listen()

void XPMP2::TCPConnection::listen ( int numConnections = 1)

listen for incoming connections

◆ listenAccept()

bool XPMP2::TCPConnection::listenAccept ( int numConnections = 1)

combines listening and accepting

◆ send()

bool XPMP2::TCPConnection::send ( const char * msg)
overridevirtual

send messages on session connection

Reimplemented from XPMP2::SocketNetworking.

Member Data Documentation

◆ f_session_addr

struct sockaddr_in XPMP2::TCPConnection::f_session_addr = {}
protected

address of the connecting counterparty

◆ f_session_socket

SOCKET XPMP2::TCPConnection::f_session_socket = INVALID_SOCKET
protected

session socket, ie. the socket opened when a counterparty connects


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