TAILIEUCHUNG - Networking and Network Programming 2 TCP/IP phần 5

Trong số các chức năng này như sau: socket () để tạo ra một điểm kết thúc của thông tin liên lạc, ràng buộc () để cung cấp cho các điểm kết thúc một tên, lắng nghe () để lắng nghe cho các kết nối đến, chấp nhận () để chấp nhận một kết nối, gửi () và sendto () để gửi dữ liệu, và recv (), recvfrom () để nhận dữ liệu. | Chapter 7 Socket Functions WSAEMSGSIZE if socket s is a datagram socket and the data was too large to fit into buf the data is truncated WSAECONNABORTED if the virtual circuit was aborted due to timeout or other failure or WSAECONNRESET if the virtual circuit was reset by the remote side. Here is an example of using the recvfrom function in a datagram server application char pszMessage 100 informational message SOCKET s socket to receive data on SOCKADDR_IN addr address of the socket tfdefine BUFSIZE 100 receive buffer size char pszBuf BUFSIZE receive buffer int nBytesRecv number of bytes received int nError error code SOCKADDR_IN addrFrom address of sender int nAddrFromLen sizeof addrFrom lengh of sender structure IN_ADDR inFrom IP address of sender s socket AF_INET SOCK_DGRAM 0 if s iNvalid_sOcket nError WSAGetLastError . else fill out the name this server will read data from AF_INET htons 2050 htonl INADDR_ANY bind the name to the socket if bind s LPSOCKADDR addr sizeof addr SOCKET_ERROR nError WSAGetLastError . else nBytesRecv recvfrom s pszBuf 100 0 LPSOCKADDR addrFrom nAddrFromLen if nBytesRecv SOCKET_ERROR nError WSAGetLastError . else got some data . copy the four byte IP address into an IP address structure memcpy inFrom 4 print an informational message wsprintf pszMessage server received d bytes from s port is d nBytesRecv inet_ntoa inFrom ntohs Part II Basics of WinSock Programming MessageBox pszMessage Datagram Server Info closesocket s Note that in this example the optional from parameter was provided. This gives the receiver the ability to send data back to the sender. This is demonstrated in the next chapter s datagram example program. As with the sendto function the recvfrom function may block. Use WSAAsyncSelect with the FD_READ event to solve this problem. Implementation is similar to that of the stream example. Closing a Socket The previous sections .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.