XPMP2
X-Plane multiplayer library 2 - using instancing
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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. 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...
 

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: