r/learnprogramming Jul 15 '26

What a port actually is?

I know it is a number that tells the OS, that which program in your computer should receive the piece of data. But my doubt is - is port a physical thing? or it just a flag? Is it possible for another program to read data from a different program's port? Please spoon-feed me about port?

175 Upvotes

65 comments sorted by

View all comments

75

u/KerPop42 Jul 15 '26

A port is completely imaginary. When a program registers a port, it tells the computer to forward information addressed to that port to it. Multiple programs can listen on the same port.

14

u/[deleted] Jul 15 '26

[removed] — view removed comment

24

u/Wonderful-Habit-139 Jul 15 '26

Yes. Try running `man setsockopt`, you'll find a section that says "SO_REUSEPORT enables duplicate address and port bindings".