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 Windows CE device. 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 Windows CE Device. You can run several instances of CHATTER on the same Windows CE device, or on different Windows CE devices, 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 Windows CE device 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.
For information on the Windows CE platforms that support this sample, see MFC for Windows CE Samples.