Experiment 2_ Network Programming (2) Concepts carded

A, stream socket

  Stream sockets relying transmission control protocol corresponding to the TCP / IP protocol suite in the TCP, for providing connection-oriented, reliable data transmission services, the service will be able to ensure error-free data without repeatedly sending, receiving and sequentially . Based on the characteristics of the stream, stream sockets used in the form of data transmission is no packet boundaries sequenced data stream.

  Stream sockets based on reliable data transfer services, this feature is a connection-oriented service, and reliable. Characteristics of the connection-oriented transport determines the cost of a large stream sockets, one and only suitable for data transmission; means that the characteristics and reliability of the upper layer application data transmission without undue consideration during the design and development missing, out of order, repeat the question. Overall, the use of stream socket adapted to select the following occasions:

1) a large amount of data transmission applications

  Stream socket for the file transfer content such large amounts of data applications, the transmission data can be arbitrarily large, it may be an ASCII text type may be a binary file. In this scenario, a large amount of data transmission, data transmission reliability is relatively high, compared to the costs and data transfer, the cost of maintaining the connection is minimal.

2) Application of high transmission reliability

  Stream sockets suitable for use in high reliability transmission applications, in this case, first transmission reliability requirements to be met, if the selected application program using UDP protocol or other unreliable data transmission service bearer errors, in order to avoid loss of data, out of order, repetition and other issues, the programmer must consider oh my God above many problems caused by the application, and the resulting complex coding cost.

Second, the communication process stream socket

Network communication process stream sockets is done on the basis of the successful establishment of the link.

1, the server communication process based on the process stream socket

In the communication process, the server process as a service provider, the passive receiving the connection request, accept or reject the request, and the established data communications connection is completed, the basic communication process is as follows:

1) Windows Sockets DLL initialization, consult the version number.

2) create a socket, specify TCP (reliable transport service) to communicate.

3) the local address and a communication port.

4) waits for a connection request from the client.

5) for data transmission.

6) closes the socket.

7) End the use of the Windows Sockets DLL, and free up resources.

2, the client communication process based on the process stream socket

In the communication process, the client process as a service requester, the initiative to request to establish a connection, the server waits for acknowledgment of the connection, the established connection and the data communication is completed, the basic communication process is as follows:

1) Windows Sockets DLL initialization, consult the version number.

2) create a socket, specify TCP (reliable transport service) to communicate.

3) specify the server address and a communication port.

4) sends a connection request to the server.

5) for data transmission.

6) closes the socket.

7) End the use of the Windows Sockets DLL, and free up resources.

Guess you like

Origin www.cnblogs.com/cyx-b/p/12446150.html