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: