2

I suppose both allow host-to-host protocols to deliver data to the proper process. But, in what way are they different?

2 Answers 2

4

Network applications are (usually) written on top of socket APIs. In some ways, sockets are entry-points for a network "pipe" that connects two or more network applications. Both sides need to open a socket to create the network "pipe". Sockets are bidirectional in nature and hence, both ends of the "pipe" can simultaneous send data to the other end and receive data from the other end. The two endpoints typically sit on different machines. Clearly, there is nothing stopping us from making them sit on the same machine.

A socket is identified by three main parameters -- one of them being the port number. The other two are: (a) IP address (IPv4 or IPv6) of the machine and (b) the transport protocol (TCP/UDP, eg.). A port number is a logical local identification point for network applications. Each host can have as many as 65,536 ports for each protocol and for each address family; typically, port numbers in the range of 0 to 1024 are standard ports and are reserved for various applications. Ports outside this range are usually available for general use. Together, these three params shoudl be unique for a given socket in the entire network. Thus, you can have two TCP socket applications sitting on the same machine but for them to be uniquely reachable, they need to be bound to different ports. There is a way to bind multiple sockets to the same port, but that is used for multicast applications.

So, the simple answer is that socket and port work together to allow two network applications to communicate. They are not competing concepts.

You might find the socket/bind sections in the Beej's Networking guide helpful. https://beej.us/guide/bgnet/html/multi/syscalls.html#socket

Sign up to request clarification or add additional context in comments.

2 Comments

For TCP, the source address, destination address, source port, and destination port, are all used to identify a socket.
@supercat agreed. For identifying globally, the TCP socket should have a unique combination of IP address and port number in the entire Internet. Once established, for identifying a flow uniquely, the 4-tuple should be unique, yes!
2

"Port" is an integral part of TCP, UDP, and other transport-layer protocols.

"Socket" is a common term for the API-level mapping between an address:protocol:port combo and an application. It has hardly anything to do with TCP/IP, and more to do with the layer above all that -- specifically the socket API being used, like BSD sockets, WinSock, or XTI. Good documentation on network protocols will never use the word in describing them. API documentation, on the other hand, almost always will.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.