Answer the question
In order to leave comments, you need to log in
What is a socket in java?
Good afternoon. Please explain what a "socket" is in Java in simple terms. What to say if asked in an interview? For myself, I always think of it as an I / O stream where you can write and where you can read, is this true?
PS Analogies from life are welcome)
Answer the question
In order to leave comments, you need to log in
Data exchange interface.
Roughly speaking, you can send data over the HTTP protocol, or you can send over a socket, the socket consists of an IP and a port. What is it for? IP is needed to identify a device on the network, each device has an IP address by which this device is available. So when we found the device by IP address, now we need to determine the client, the program with which we will exchange data, for this we need a port, the port is responsible for "discovering" the program.
Now we can send and receive data on the socket, for this we need to create connections on both sides, unlike HTTP, data can be sent not only by the client, but also by the server.
This is in short.
A socket in Java is no different from sockets in other languages.
An analogy in the life of a socket is, roughly speaking, this is a socket / connector on some kind of piece of iron, for example, on a regular router. Naturally, this router has all the connectors numbered (in the concept of a socket, this is the port number 0-65535). You plug the patch cord into a free port on your router and the other end into a free port on your PC. This is how the socket connection happened.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question