tailieunhanh - Networking and Network Programming 2 TCP/IP phần 7

Chương này bàn về các lớp học CDatagramSocket. Lớp này đơn giản hóa sự tương tác của một ứng dụng với một ổ cắm gói. Lớp này chịu trách nhiệm cho việc tạo ra một ổ cắm gói, ràng buộc tùy chọn ổ cắm một cái tên, gửi và nhận dữ liệu, và phá hủy các ổ cắm. Khai báo lớp như sau: | Part III WinSock Class Library This chapter discusses the CDatagramSocket class. This class simplifies an application s interaction with a datagram socket. This class is responsible for creating a datagram socket optionally binding the socket to a name sending and receiving data and destroying the socket. The class declaration is as follows lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll CDatagramSocket class CDatagramSocket public CWnd private CWnd m_pParentWnd window to receive event notification UINT m_uMsg message to send to m_pParentWnd on event SOCKET m_s socket handle SOCKADDR_IN m_sinLocal name bound to socket m_s int m_nLastError last WinSock error BOOL m_bServer TRUE if socket m_s is bound to a name CPtrList m_listWrite data waiting to be sent CPtrList m_listRead data read public CDatagramSocket CWnd pParentWnd UINT uMsg virtual -CDatagramSocket int CreateSocket int nLocalPort int CreateSocket LPSTR pszLocalService NULL int DestroySocket int Write int nLen LPVOID pData LPSTR pszRemoteName int nRemotePort int Write int nLen LPVOID pData LPSTR pszRemoteName LPSTR pszRemoteService int Write int nLen LPVOID pData LPSOCKADDR_IN psinRemote LPVOID Read LPINT pnLen LpSoCKaDdR_IN psinRemote NULL int LastError return m_nLastError private void InitVars BOOL bInitLastError TRUE LONG HandleRead WPARAM wParam LPARAM lParam LONG HandleWrite WPARAM wParam LPARAM lParam ll message map functions protected ll AFX_MSG CStreamSocket afx_msg LONG OnWinSockEvent WPARAM wParam LPARAM lParam DECLARE_MESSAGE_MAP The class contains several private member variables that are inaccessible outside of the class implementation. Of particular interest are the m_listWrite and m_listRead member variables. These CPtrObject-derived objects maintain pointers to the incoming and outgoing data. The data maintained by these lists has the following structure structure used for datagram socket read write queue typedef struct tagDATAGRAMDATA LPVOID pData int nLen .

TỪ KHÓA LIÊN QUAN