StartListener

HRESULT StartListener( CEvent* pReadEvent );

To use CSock to receive messages, call StartListener(&eventRead) to start listener. Then you can wait for the read event represented by eventRead to occur, at which point you would use the Read method to retrieve the message. This allows you to wait on both the read event and your own exit event (using the Win32 function WaitForMultipleObjects).

Note that it does not currently have the option of notifying you with a Windows Message so you have to either dedicate a thread to waiting for a message to arrive or else poll the read event which would be inefficient. You can see how additional threads around CSock are used in the Messaging Project to implement asynchronous messaging.

Read

HRESULT Read( CBuffer &bufMessage );

You will be notified that a message is ready via the read event that was specified in the StartListener method. At this point the message has already been brought into memory. However, in the current implementation of CSock, the listener will not continue listening until you have retrieved the buffer from your CSock object by calling Read(bufMessage).

In the following example, one message is received if it arrives within 5 seconds:

StopListener

Call StopListener() to stop the listener in your CSock object. This is also automatically called in the CSock destructor, so it is not necessary to call it explicitly.

Ping

HRESULT Ping( CString csAddress );

Call Ping(csAddress) to test if there is a TCP/IP network connection to the specified address. This is a synchronous function and occassionally under some circumstances there can be a long delay when the address is not resolved quickly.

As with the Send method, the address can be in the form of an internet address string "206.83.84.176", the name of the computer on the LAN such as "machine2", or the fully qualified domain name such as "firstobject.com".

ResolveAddress

HRESULT ResolveAddress( CString csName );

Call ResolveAddress(csName) to determine the IP address of a named remote machine. The csName string refers to a computer on your LAN such as "machine2" or a fully qualified domain name.