What is the difference between a port and a socket?

后端 未结 30 2098
旧巷少年郎
旧巷少年郎 2020-11-22 14:31

This was a question raised by one of the software engineers in my organisation. I\'m interested in the broadest definition.

30条回答
  •  梦谈多话
    2020-11-22 15:18

    Port and socket can be compared to the Bank Branch.

    The building number of the "Bank" is analogous to IP address. A bank has got different sections like:

    1. Savings account department
    2. Personal loan department
    3. Home loan department
    4. Grievance department

    So 1 (savings account department), 2 (personal loan department), 3 (home loan department) and 4 (grievance department) are ports.

    Now let us say you go to open a savings account, you go to the bank (IP address), then you go to "savings account department" (port number 1), then you meet one of the employees working under "savings account department". Let us call him SAVINGACCOUNT_EMPLOYEE1 for opening account.

    SAVINGACCOUNT_EMPLOYEE1 is your socket descriptor, so there may be SAVINGACCOUNT_EMPLOYEE1 to SAVINGACCOUNT_EMPLOYEEN. These are all socket descriptors.

    Likewise, other departments will be having employess working under them and they are analogous to socket.

提交回复
热议问题