Our application is callingSocket ()Function, BIND ()After the function is created, it is created locally.SocketStruct,SockStruct, andSocket,SockThese two structs followINodes and file handles are combinedSocketThe operation set of the specified protocol is associatedSockStruct, used inSocketAfter the protocol is specified, use this operation set to complete related operations.BIND ()The function returns an unused local port number.(Generally greater1024Because0 ~ 1024It is a well-known port number and is retained for specific purposes. If the port number is not specified by the Nutrition Program, it is annoying to find the idle port number.), Used to indicate the currentSockProcess, andIPBindSockIs used to indicate where the data will be sent to the network.
All of these are done locally, and there is no such thing as the transport layer, the network layer, or the link layer.TCP/IP/MacSo,Socket/BindThe call of the two functions is actually only a preparation action, to do the basic work for creating a connection, that isConnectFunction debut ready stage
ConnectThe function createsSYNData, sent to the remoteIP(ConnectFunction parameter ).SYNThe signal will beTCP/IP/MacThe three data structures are packaged and transmitted to the remote address through the transport layer, network layer, and link layer until the network. Then, the remote address is locally sent back to the remote address. Once the remote address is listened and receivedSYNSignal, a new process will be created, and then a process will be createdSocket,SockAnd reply toACKSignal passTCP/IP/MacThree data structures are packaged and then transmitted to the remote network adapter through the remote transmission layer, network layer, and link layer. The remote network adapter sends data to the network.IPAddress: LocalIP, AfterARPYou can find the local Nic on the networkMac, And then find the network card, and then send the data to the local end, the local end receivesACKAfter the signal is sent, send a responseACKIf the signal is sent to the remote end, a link is established successfully,<TCPThree-way handshake>Later data will be transmitted on this link, while the routes passed through in the middle may be different, but the two endpoints will remain unchanged. The form is roughly<Network Routing>Because the intermediate route is adjusted at any time according to the network conditions, useARPTechnology.