I've heard a lot of different definitions online, and having trouble understanding what a socket is.
It'd be great if someone could shine a light where it's all dark for me.
-
1In what context precisely?– RamhoundMar 22, 2016 at 19:36
-
@Ramhound: Does it matter, really? That's the problem -- in general context when people speak about sockets.– JosephMar 22, 2016 at 19:36
-
A motherboard CPU socket? The software abstraction for a communication endpoint, or a wall socket? Reduce the scope of your question. I just thought of 3 different types of sockets. All three are within the scope of this website, only one, I presume is within the scope of your actual question.– RamhoundMar 22, 2016 at 19:38
-
Here is a related question– RamhoundMar 22, 2016 at 19:45
-
2en.wikipedia.org/wiki/Network_socket as I assume you mean a network socket.– Eric FMar 22, 2016 at 19:57
3 Answers
An analogy that I've heard before is that a network socket is similar to a regular electrical wall socket in the way that both are used to make a connection to another location. More precisely, a network socket is something that is opened or closed just like a file, but instead of reading or writing data to a disk, you are sending and/or receiving network packets. The socket is opened with a command (depending on what language or platform you are using) which will cause (in the case of a TCP connection) a 3-way handshake that initiates the connection. Sending data to the socket will cause that data to be sent through to the other system.
Just like a file, it should be closed when you are finished with it, and there's another command that will do that as well, again depending on your OS and platform.
Hopefully that makes sense.
Network Socket Address is a combination of IP address and port number separated by colon.
Eg: 192.168.1.1:23
This means 192.168.1.1 is listening on port 23 and can accept telnet data which is coming to 192.168.1.1
Likewise you can say 192.168.1.1:80 is a network socket and is ready to process HTTP data.
This can be googled easy. But since I have time:
A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent to. An endpoint is a combination of an IP address and a port number.
via Oracle Tutorial
-
A socket is not an endpoint communication. Socket is a combination of IP address and port number separated by colon. Mar 23, 2016 at 13:31