I have a weird query. I have learned that a socket is a combination of IP and Port. So what is socket descriptor? Is it just an integer? What does it do?
Can I have to different socket descriptors on the same port? If yes, then can those be of different types (TCP/UDP)?
I know these are silly questions; I have been blindly using SD for quite a time now 😛
TCP and UDP are independent, so you can have TCP and UDP sockets on the same port.
A socket descriptor is to a socket as a file descriptor is to a file.
A TCP connection is actually defined by the tuple: local IP, local port, remote IP, remote port. You can have multiple connections with the same local IP and port, as long as they have different remote IP and/or port.
For instance, a web server uses its local port 80 for all the connections. But each client connection will either come from a different machine (and hence a different remote IP) or different sockets on the same machine (so they’ll have the same remote IP but different remote ports).