In: Computer Science
4. How does a client socket interact with a server socket to exchange data?
Sockets are basically use for client server interaction.A socket has a typical flow of events. Socket is basically a flow of event.In connection oriented client to server the socket waits for the server to send the request to the client.For doing this the server binds and address which will be later use to find out the client.Once the address is established then server waits for the client to request a service.For connecting the client to the server socket is used.The server performs the client's request and sends the reply back to the client.
The socket Api created an end point by returning and endpoint descriptor.which is useful for binding the unique address to the socket.After this one listen API is created which is created before accept API.
Client use a connect API to connect to the server and server uses accept API to connect to the client and once the connection is being established then there are many data transfer API like send(),recv(),read().
For termination of the connection server or client issues close() API for closing the connection