In java, two sockets can be connected by client and server programming. Server socket in server side listens to the TCP port and the client sends the data request through this socket.