Reputation: 2584
I suppose both allow host-to-host protocols to deliver data to the proper process. But, in what way are they different?
Upvotes: 2
Views: 364
Reputation: 4666
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
Upvotes: 4
Reputation: 86506
"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.
Upvotes: 2