What is a socket and how does it work?

Hello guys, I have a quick question, previously I wanted to know what a socket is and how it works. I read a bit about networking in general and then tried to understand how sockets work. So basically, from what I've understood: 1. A socket is just an endpoint that enables us to read data or write data (just like a file can be read from or written to.) 2. Now, in the TCP/IP model, a socket is created, we give it an IP and a Port number. Then TCP will just to its things, wrap all packets, ensure they are assembled in required order or retransmit lost packets etc. 3. The underneath layer will then deliver the packets by some way. (Sockets doesn't do the communication themselves, instead the layers in the TCP/IP model does that, so socket is kind of just a label? Like ok this is the gate that is allowed to send data or receive data?) Can someone confirm whether the things said above is correct please... feel free to add up to it if needed.
3 Replies
Rägnar O'ock
Rägnar O'ock2d ago
I just saw a video about that yesterday, let me find it again. It was very well explained. But it looks like you got most of the important info already (though some details might be not technically accurate, but that's not really important)
ἔρως
ἔρως2d ago
A socket is just an endpoint that enables us to read data or write data (just like a file can be read from or written to.)
not all sockets are endpoints: some are just files. mysql uses file sockets, for example. you can use file sockets to communicate between multiple processes, without the whole tcp/ip overhead. the kernel takes care of everything for you

Did you find this page helpful?