WinSock programming entry-3. Create a socket

Source: Internet
Author: User
Use the socket function to create a socket. The socket type is defined in Winsock. h:

Socket socket (int af, int type, int Protocol );

AF is the Protocol address family. Here we use IPv4, which must be af_inet

Type is socket type. If TCP/IP is used, type is set to sock_stream. If UDP is used, sock_dgram is used.

Protocol is used to limit specific transmission when multiple entries are provided for the given address family and socket type. For TCP, its value is ipproto_tcp, while UDP is ipproto_udp.

Winsock uses the setsockopt, getsockopt, ioctlsocket, and wsaioctl functions to control various socket options and behaviors. For simple Winsock applications, we may not need to use them. once a socket is successfully established, you can prepare to send and receive data through the socket. winsock has two communication modes: connection-oriented communication mode and connectionless communication mode.

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.