Lấy con trỏ vào hộp danh sách được sử dụng cho các thông báo trạng thái Lập trình với Thư viện Class WinSockdữ liệu khối trong hàng đợi / / nên không bao giờ xảy ra nhưng chắc chắn rằng bộ nhớ được giải phóng chỉ trong trường hợp pDataRead | 06 Part IV Programming with the WinSock Class Library Listing . continued get pointer to list box used for status messages CListBox plb CListBox GetDlgItem IDC_LIST_STATUS switch wParam case CWINSOCK_DONE_WRITING lParam pointer to data that was sent pDataWritten LPVOID lParam wsprintf pszMessage Heartbeat sent plb- InsertString 0 pszMessage m_pszHeartbeat 0 same as pDataWritten 0 break case CWINSOCK_ERROR_WRITING lParam pointer to data that generated error sending pDataWritten LPVOID lParam wsprintf pszMessage Error sending heartbeat plb- InsertString 0 pszMessage m_pszHeartbeat 0 same as pDataWritten 0 break case CWINSOCK_DONE_READING lParam data chunks in gueue should never happen but make sure the memory is freed just in case pDataRead m_pDatagram- Read nLen free pDataRead break case CWINSOCK_ERROR_READING break default break return 0L CServerView OnTimer Sends periodic heartbeats to the connected client through the datagram. void CServerView OnTimer UINT nIDEvent char pszMessage 1000 informational message ifdef HEARTBEAT_TEST static int nHeartbeatTest 0 nHeartbeatTest if nHeartbeatTest 10 ỊỊ nHeartbeatTest 11 ỊỊ nHeartbeatTest 20 ỊỊ nHeartbeatTest 21 return endif Chapter 15 Practical Client Server Database Application make sure we are not sending out of a bad datagram socket if m_pDatagram NULL return get pointer to list box used for status messages CLiStBox plb CListBox GetDlgItem IDC_LIST_STATUS send the buffer unless the previous send hasn t completed yet if m_pszHeartbeat 0 lstrcpy m_pszHeartbeat HEARTBEAT_STRING be sure to send terminating NULL character if m_pDatagram- Write lstrlen m_pszHeartbeat 1 m_pszHeartbeat m_sinClient CWInSock_NOeRroR m_pszHeartbeat 0 wsprintf pszMessage Error sending heartbeat plb- InsertString 0 pszMessage CFormView OnTimer nIDEvent Figures and show the client and server in action. FIGURE . The client INICLNT Summary This chapter demonstrates the use of the CWinSock CDatagramSocket and CStreamSocket objects. It