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

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

#include <tcp.h>

Inheritance diagram for wex::tcp:
wex::gui

Public Member Functions

 tcp (gui *parent)
 CTOR. More...
 
void RetryConnectServer (bool f)
 Configure client() blocking. More...
 
void client (const std::string &ipaddr="127.0.0.1", const std::string &port="27678")
 Create client socket connected to server. More...
 
void server (const std::string &port="27654")
 Create server socket waiting for connection requests. More...
 
bool isConnected ()
 true if valid connection
 
void send (const std::string &msg)
 send message to peer More...
 
void send (const std::vector< unsigned char > &msg)
 
void read ()
 asynchronous read message on tcp connection More...
 
std::string readMsg () const
 Get last message from peer.
 
std::string serverPort () const
 
- Public Member Functions inherited from wex::gui
 gui ()
 Construct top level window with no parent. More...
 
 gui (gui *parent, const char *window_class="windex", unsigned long style=WS_CHILD, unsigned long exstyle=WS_EX_CONTROLPARENT)
 Construct child of a parent. More...
 
void child (gui *w)
 register child on this window
 
children_t & children ()
 get vector of children
 
guiparent ()
 
guifind (int id)
 find child window with specified id
 
void focus ()
 
void bgcolor (int color)
 Change background color. More...
 
void nobgerase ()
 
void enable (bool f=true)
 Enable/Disable, default enable.
 
bool isEnabled () const
 
void fontHeight (int h)
 Change font height for this and all child windows.
 
void fontName (const std::string &name)
 
void icon (const std::string &iconfilename)
 Change icon. More...
 
void cursor (char *cursorID)
 
int id ()
 
int bgcolor () const
 
void textColor (int c)
 Set text color. More...
 
void text (const std::string &text)
 
std::string text () const
 
void scroll (bool fHoriz=true)
 Add scrollbars. More...
 
void scrollRange (int width, int height)
 Set the scrolling range. More...
 
sMouse getMouseStatus ()
 Get mouse status. More...
 
void run ()
 Run the windows message loop. More...
 
void tooltip (const std::string &text, int width=0)
 Add tooltip that pops up helpfully when mouse cursor hovers over widget. More...
 
virtual LRESULT WindowMessageHandler (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
virtual void show (bool f=true)
 Show window and all children.
 
void showModal (gui &appWindow)
 Show this window and suspend all other windows interactions until this is closed. More...
 
void endModal ()
 Stop modal interaction and close window.
 
void update ()
 force widget to redraw completely More...
 
void move (const std::vector< int > &r)
 Move the window. More...
 
void size (int w, int h)
 Change size without moving top left corner. More...
 
void move (int x, int y)
 Change position without changing size. More...
 
void move (int x, int y, int w, int h)
 
std::vector< int > size ()
 Size of window client area. More...
 
std::vector< int > lefttop ()
 
eventhandlerevents ()
 Get event handler.
 
HWND handle ()
 get window handle
 
void delete_list (std::vector< HWND > *list)
 set delete list for when gui is detroyed
 
void setfont (LOGFONT &logfont, HFONT &font)
 change font for this and all child windows
 
void setAsyncReadCompleteMsgID (int id)
 

Additional Inherited Members

- Protected Member Functions inherited from wex::gui
void Create (HWND parent, const char *window_class, DWORD style, DWORD exstyle=0, int id=0)
 Create the managed window. More...
 
void font (LOGFONT &logfont, HFONT &font)
 get font details More...
 
void createNewFont ()
 Replace font used by this and child windows from logfont.
 
virtual void draw (PAINTSTRUCT &ps)
 
int NewID ()
 Create new, unique ID for gui element. More...
 
int scrollMove (SCROLLINFO &si, int code)
 
- Protected Attributes inherited from wex::gui
HWND myHandle
 
guimyParent
 
eventhandler myEvents
 
int myBGColor
 
int myTextColor
 
HBRUSH myBGBrush
 
LOGFONT myLogFont
 
HFONT myFont
 
std::vector< HWND > * myDeleteList
 
std::string myText
 
int myID
 
std::vector< gui * > myChild
 gui elements to be displayed in this window
 
bool myfModal
 true if element is being shown as modal
 
bool myfEnabled
 true if not disabled
 
bool myfnobgerase
 
HWND myToolTip
 
unsigned int myAsyncReadCompleteMsgID
 handle to tooltip control for this gui element
 
char * myCursorID
 
bool myfScrollHoriz
 

Detailed Description

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

Events ( peer connection, read completion ) generate messages to the parent window specified in the constructor.

For sample code, see https://github.com/JamesBremner/windex/blob/master/demo/tcpdemo.cpp

Constructor & Destructor Documentation

◆ tcp()

wex::tcp::tcp ( gui parent)
inline

CTOR.

Parameters
[in]parentwindow that will receive event messages

Member Function Documentation

◆ client()

void wex::tcp::client ( const std::string &  ipaddr = "127.0.0.1",
const std::string &  port = "27678" 
)
inline

Create client socket connected to server.

Parameters
[in]ipaddrIP address or name of server, defaults to same computer
[in]portdefaults to 27678

◆ read()

void wex::tcp::read ( )
inline

asynchronous read message on tcp connection

Throws exception if no tcp connection

Returns immediatly.

When message is received, the parent window will receive tcpRead event

If the connection is closed, or suffers any error the same event will be invoked, so the isConnected() method should be checked.

◆ RetryConnectServer()

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

Configure client() blocking.

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

◆ send()

void wex::tcp::send ( const std::string &  msg)
inline

send message to peer

Parameters
[in]msg

◆ server()

void wex::tcp::server ( const std::string &  port = "27654")
inline

Create server socket waiting for connection requests.

Parameters
[in]port,defaultsto 27654

Starts listening for client connection. Returns immediatly throws runtime_error exception on error sends eventMsgID::tcpServerAccept message to parent window when new client accepted

One connection will be accepted. This can be called again if the connection is closed to wait for another client.


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