MFC section 2-Network Programming

Source: Internet
Author: User

Use socket programming.

1. Socket library is required. You need to know the version of the applied socket library, which is represented by the word type: makeword. After loading, check whether the requested version is obtained.

2. Create a socket. Socket socket struct.

3. Bind the socket object to the sockaddr socket address. In TCP/IP programming, sockaddr_in can be used to replace sockaddr (both represent the address space ). Sockaddr_in includes sin_family: address family. If the IP address is always af_inet, sin_port is the port address in the byte sequence of the network, and sin_addr is the Host IP address and the in_addr structure.

In sockaddr_in, the network is in byte order. Generally, port addresses such as 6000 and IP address inaddr_any are in the host byte order. To convert the port address, htonl () htons () is used ()

4. Request connect from another socket, accept the client's connection request accept, and return the socket type

5. send messages to connected sockets send messages to unconnected sockets sendto

6. Accept information Recv from connected socket and accept information recvfrom () from unconnected socket ()

 

In addition, note: the standard input and output header file stdio. h

Contains the socket library, header file: winsock2.h

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.