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

Hình cho thấy dòng chảy của WinSock chức năng cuộc gọi cho một khách hàng và máy chủ sử dụng TCP. Hình cho thấy một dòng chảy tương tự như các cuộc gọi chức năng WinSock, nhưng thời gian này cho một khách hàng và máy chủ sử dụng UDP. | 0 Part II Basics of WinSock Programming Listing . continued END_MESSAGE_MAP lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll CMainView message handlers 11IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII ll CMainView OnAsyncSelect ll ll Receives data from a client and echoes the data back to the sending client. ll While there is data yet to be sent back to the sending client the server ll will not receive any more data. a single data buffer is used for ll incoming and outgoing data ll LONG CMainView OnAsyncSelect WPARAM wParam LPARAM lParam char pszMessage 100 ll informational message static char pBuf 101 ll sendlrecv buffer int nBytesRecv ll number of bytes received int nBytesSent ll number of bytes sent static int nBytesToSend 0 ll number of bytes to send int nError ll WinSock error static SOCKADDR_IN addrFrom ll address of client static int nAddrFromLen sizeof addrFrom ll length of client address struct static IN_ADDR inFrom ll IP address of client ll get pointer to list box used for status messages CListBox plb CListBox GetDlgItem IDC_LIST_STATUS ll check for an error if WSAGETSELECTERROR lParam 0 wsprintf pszMessage Datagrem echo server async select got error d WSAGETSELECTERROR lParam plb- InsertString 0 pszMessage return 0L ll what event are we being notified of switch WSAGETSELECTEVENT lParam case FD_WRITE ll echo the data back to the client plb- InsertString 0 FD_WRITE ll are there bytes to send if nBytesToSend 0 ll send the data nBytesSent sendto m_s pBuf nBytesToSend 0 LPSOCKADDR addrFrom nAddrFromLen ll check for send error if nBytesSent SOCKET_ERROR ll if the error is just that the send would block Chapter 8 Sample Applications don t do ll get another FD_WRITE soon nError WSAGetLastErrorO if nError WSAEWOULDbLOCk wsprintf pszMessage Error d sending data to s d nError inet_ntoa inFrom ntohs plb- InsertString 0 pszMessage nBytesToSend 0 just in case the FD_READ was .

TỪ KHÓA LIÊN QUAN