Network protocol stack 5: Before the connect () function

Source: Internet
Author: User

 

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.

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.