Socket Programming Question:
Download Job Interview Questions and Answers PDF
How Sockets can be used to write client-server applications using a connection-oriented client-server technique?
![Socket Programming Interview Answer Socket Programming Interview Question](https://globalguideline.com/public/images/interview/6.png)
Answer:
Sockets can be used to write client-server applications using a connection-oriented client-server technique. Some characteristics of this technique include:
* The server can handle multiple client requests for connection and service.
* The server responds to any one client's request independently of all other clients.
* A client knows how to establish a connection with the server.
The client-server connection, when established, remains in existence until either the client or the server explicitly breaks it, much like a trouble-free telephone call. The socket used for this connection is called a connection-oriented socket.
The socket type is specified as SOCK_STREAM. As a result, the process receiving a message processes that message by the following rules:
* The data transmitted has no boundaries.
* All bytes in a received message must be read before the next message can be processed.
* Bytes in a received message can be read in a loop program control structure since no data bytes are discarded.
* The server will usually fork() a child process upon establishment of a client connection.
* This child server process is designed to communicate with exactly one client process.
* The child server process performs the requested service for its connected client.
* The child server process terminates when the service request has been completed.
Functions listen() and accept() enable the server to listen for service requests. read() and write() may be used by client and server to send/receive messages; send() and recv() may also be used.
* The server can handle multiple client requests for connection and service.
* The server responds to any one client's request independently of all other clients.
* A client knows how to establish a connection with the server.
The client-server connection, when established, remains in existence until either the client or the server explicitly breaks it, much like a trouble-free telephone call. The socket used for this connection is called a connection-oriented socket.
The socket type is specified as SOCK_STREAM. As a result, the process receiving a message processes that message by the following rules:
* The data transmitted has no boundaries.
* All bytes in a received message must be read before the next message can be processed.
* Bytes in a received message can be read in a loop program control structure since no data bytes are discarded.
* The server will usually fork() a child process upon establishment of a client connection.
* This child server process is designed to communicate with exactly one client process.
* The child server process performs the requested service for its connected client.
* The child server process terminates when the service request has been completed.
Functions listen() and accept() enable the server to listen for service requests. read() and write() may be used by client and server to send/receive messages; send() and recv() may also be used.
Download Socket Programming Interview Questions And Answers
PDF
Previous Question | Next Question |
How to disposing of a Socket? | How to make a Socket a Listen-only Connection Endpoint - listen()? |