WINDEX
Public Member Functions | List of all members
wex::cSocket Class Reference

Read/Write to TCP/IP socket, client or server. More...

#include <tcp.h>

Public Member Functions

void server (const std::string &port, std::function< void(std::string &port)> connectHandler, std::function< void(std::string &port, const std::string &msg)> readHandler)
 Start server. More...
 
void RetryConnectServer (bool f)
 Configure client() blocking. More...
 
void client (const std::string &ipaddr, const std::string &port, std::function< void(std::string &port, const std::string &msg)> readHandler)
 Connect to server. More...
 
bool isConnected ()
 
void send (const std::string &msg)
 Send message to connected peer.
 
void run ()
 Start the windex event handler. More...
 

Detailed Description

Read/Write to TCP/IP socket, client or server.

Events ( peer connection, read completion ) are handled by callbacks

This does not require a parent window and so is suitable for console applications

Member Function Documentation

◆ client()

void wex::cSocket::client ( const std::string &  ipaddr,
const std::string &  port,
std::function< void(std::string &port, const std::string &msg)>  readHandler 
)
inline

Connect to server.

Parameters
[in]ipaddr
[in]port
[in]readhandlerevent handler to call when server sends a message

◆ RetryConnectServer()

void wex::cSocket::RetryConnectServer ( bool  f)
inline

Configure client() blocking.

true: keep trying until connection made ( default on construction ) false: if connection refused return after one attempt

◆ run()

void wex::cSocket::run ( )
inline

Start the windex event handler.

This blocks!

Call this once when everything has been setup

This is used by console type applications. GUI applications should not call this They will call run on the main application window when setup is complete

◆ server()

void wex::cSocket::server ( const std::string &  port,
std::function< void(std::string &port)>  connectHandler,
std::function< void(std::string &port, const std::string &msg)>  readHandler 
)
inline

Start server.

Parameters
[in]portto listen for clients
[in]connectHandlerevent handler to call when client connects
[in]readHandlerevent handler to call when client sends a message

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