Summary of VC ++ network programming (1)

Source: Internet
Author: User
Tags htons

1. socket programming principles

A complete inter-network communication process must be composed of two processes and can only use the same high-level protocol. That is to say, TCP is not allowed for communication, and UDP is used for the other end. A complete network information must be identified by a quintuple: Protocol, local address, local port number, remote address, and remote port number.

1.1 Client/Server Communication Model

In Client/Server mode, we turn the party requesting the service into a customer, and the party providing a service is called the Server)

A service program listens to service requests at a well-known address, that is, the service process remains dormant until a client initiates a connection request to the service address. At this moment, the service program is "awakened" and provides services to the customer-responds appropriately to the customer's request. Although link-based services are the standard for designing client/server applications, some services can also be provided through connectionless interfaces.

The request/Response Process of the customer and/server is as follows:

Comment (lib, "WS2_32") <stdio. h> printf (= MAKEWORD (, (WSAStartup (wVersionRequested, & wsaData )! = SOCKET s = (s ==== htons (= inet_addr (connect (s, (sockaddr *) & Sadd, (Sadd) = printf (

========= Server

#include <winsock2.h><stdio.h> comment(lib,"ws2_32") main( argc, *    WORD wVersionRequested = MAKEWORD(,(WSAStartup(wVersionRequested,&wsaData) != ,&wsaData.szDescription[,&wsaData.szSystemStatus[=(s ==    == htons(= inet_addr((bind(s,(sockaddr*)&Sadd,(Sadd)) ==      ( listen( s,  )==      caddLen= = accept( s,( sockaddr*)& Cadd,& ( c== ,& ( xx==  || xx==  

Running result:

Related Article

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.