I am studying os concepts and I found socket as the end point of communication. Now what exactly is a socket? Is it a process through means of which a system communicates? Thanks in advance
- 1Did you read e.g. en.wikipedia.org/wiki/Network_socket?Oliver Charlesworth– Oliver Charlesworth2015-02-21 17:11:51 +00:00Commented Feb 21, 2015 at 17:11
- I have read. It says "Inter Process Communication Flow".Does this mean it is a process? If so how each process gets its IP?user3718000– user37180002015-02-21 17:18:12 +00:00Commented Feb 21, 2015 at 17:18
- 1Your question boils down to 'teach me about networking and sockets'. It's WAY too broad.Martin James– Martin James2015-02-21 21:45:46 +00:00Commented Feb 21, 2015 at 21:45
- Each device get ip by dhcp protocol or hardcode by administrator.Aditya_Giri– Aditya_Giri2025-07-14 11:20:37 +00:00Commented Jul 14 at 11:20
2 Answers
From reading the Wikipedia article, I can see why you may be confused.
A socket is a virtual device. That is, it is a device that is written in software and has no physical device. Thus, you can read to and write from a socket, like you would do to a terminal.
Sockets work in pairs to communicate and are usually bidirectional. One reads to socket (A) and writes to socket (B) --- or ---- writes to socket (A) and reads from socket --- or --- switches back and forth.
Generally sockets are used for network communications. They can usually support multiple protocols (TPC/IP, UDP/IP, even DECnet--the gamut depends upon the underlying system).
Sockets can be used for interprocess communication on a single system as well.
Comments
Most of the c-family languages and their based languages implement socket as Berkeley sockets which are implemented as file descriptors. From Wikipedia:
In the traditional implementation of Unix, file descriptors index into a per-process file descriptor table maintained by the kernel, that in turn indexes into a system-wide table of files opened by all processes, called the file table. This table records the mode with which the file (or other resource) has been opened: for reading, writing, appending, and possibly other modes. It also indexes into a third table called the inode table that describes the actual underlying files.[3] To perform input or output, the process passes the file descriptor to the kernel through a system call, and the kernel will access the file on behalf of the process. The process does not have direct access to the file or inode tables.
So on a high-level, sockets are implemented as files whose file-descriptors or handles are referenced as identifier to the socket.