The CHATTER and CHATSRVR sample programs demonstrate how to use the CCeSocket class to create and use data sockets and listening sockets in Windows CE applications.
To execute these applications, you will need a desktop computer and a Handheld PC (H/PC). Start CHATSRVR on the desktop computer. CHATSRVR displays a dialog with a single edit box. Enter a number between 0 and 99, to assign a listening port.
Start CHATTER on the H/PC. You can run several instances of CHATTER on the same H/PC, or on different H/PCs, connected to the same instance of CHATSRVR. CHATTER displays a dialog in which you enter the following three elements:
The CHATTER user interface consists of a static splitter window with two panes, a chat view and a send view. When you enter a message in the send view pane and press the enter key, CHATTER sends the message, prefixed by its client handle, through its data socket to the listening socket on the H/PC running CHATSRVR.
CHATSRVR receives notification of the incoming connection on its listening socket, creates a data socket to receive the connection, and adds the new socket to its connection list. CHATSRVR reads the message from the data socket, and then sends that message to all the instances of CHATTER that are currently connected to its data sockets.
Each running instance of CHATTER receives the message through its data socket, and then displays it in the chat view pane of its splitter window. When an instance of CHATTER closes its data socket, it sends a final message to CHATSRVR with a flag set to indicate that the socket is being closed.
When CHATSRVR receives this message, it obtains its socket window handle by invoking the new WCE MFC API function, AfxGetCeSocketWindow, and sends this window a WM_SOCKET_NOTIFY message with the wParam set to the client socket's SOCKET handle and the lParam set to FD_CLOSE. This message is mapped to the OnClose handler of the socket connected to that client. Systems that support true asynchronous socket notifications provide this behavior automatically but, in Windows CE, you have to code it yourself.
These samples demonstrate the following keywords:
You can find the CHATTER project files in the Wce\Samples\Mfc\CHATTER directory, and the CHATSRVR project files in the Wce\Samples\Mfc\CHATSRVR directory.
To build the CHATTER and CHATSRVR samples, follow the procedure described in Building the Sample Applications, selecting one or more of the following project configurations.