Types

typedef unsigned int UNative; typedef unsigned int BoolN; typedef signed int SNative; typedef short * PWChar; typedef unsigned char * PByte; typedef void * PVoid;

For compatibility reasons, I'm trying to stick to types that are all 32 bits when compiled for Win32.

PWChar is a pointer to a UTF-16 code unit.

PVoid is usually used for pointers to clients, pointers to servers, or pointers that can be either.

Functions

PVoid ClientCreate(void);

Creates a new client object, and returns it.

UNative ClientConnect(PVoid pClientOb, PWChar pTarHost);

Connects the client to the specified server. The server can be specified by host name(like "darekun.dnsdojo.net") or by IP in dotted decimal form(like "76.88.79.255"). This can be implemented by simply trying inet_addr(), then if it doesn't work gethostbyname().

Returns ERROR_SUCCESS on success, some other Windows error code on failure.

UNative ClientReceiveData(PVoid pClientOb, PByte pReceiveBuf, UNative & ReceiveBufSize);
UNative ServerReceiveData(PVoid pServerConnection, PByte pReceiveBuf, UNative & ReceiveBufSize);

Dequeues data queued by the connection's receive thread. On entry, ReceiveBufSize is the available bytes in the buffer pointed to by pReceiveBuf; on return, ReceiveBufSize is bytes of data that were transferred to the buffer.

Returns ERROR_SUCCESS on success, some other Windows error code on failure.

UNative SetClientReceiveMsg(PVoid pClientOb, UNative NewWindow, UNative NewMsg, UNative NewWParam);
UNative SetServerReceiveMsg(PVoid pServerConnection, UNative NewWindow, UNative NewMsg, UNative NewWParam);

Sets a server connection or client to post Windows messages when it receives data. NewReceiveMsg is the message to use(like WM_USER), NewWParam is the WParam to pass in the messages(for context), and the LParam to pass in the messages is a pointer to the client or to the server connection. Something like this: PostMessage(NewWindow, NewMsg, NewWParam, this);.

Returns ERROR_SUCCESS on success, some other Windows error code on failure.

UNative SetClientReceiveSemaphore(PVoid pClientOb, UNative NewSem);
UNative SetServerReceiveSemaphore(PVoid pServerConnection, UNative NewSem);

Sets a server connection or client to release a semaphore when it receives data. Something like this: ReleaseSemaphore(NewSem, 1, NULL);.

Returns ERROR_SUCCESS on success, some other Windows error code on failure.

void ServerGo(PVoid ServerOb);

Basically passes the current thread to the specified server; doesn't return until the server is done and ready to be passed to CloseServer().