- Unix Socket - Summary
- Unix Socket - Client Example
- Unix Socket - Server Example
- Unix Socket - Helper Functions
- Unix Socket - Core Functions
- Unix Socket - IP Address Functions
- Unix Socket - Network Byte Orders
- Unix Socket - Ports and Services
- Unix Socket - Structures
- Unix Socket - Client Server Model
- Unix Socket - Network Host Names
- Unix Socket - Network Addresses
- Unix Socket - What is a Socket?
- Unix Socket - Home
Unix Socket Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Unix Socket - Cpent Server Model
Most of the Net Apppcations use the Cpent-Server architecture, which refers to two processes or two apppcations that communicate with each other to exchange some information. One of the two processes acts as a cpent process, and another process acts as a server.
Cpent Process
This is the process, which typically makes a request for information. After getting the response, this process may terminate or may do some other processing.
Example, Internet Browser works as a cpent apppcation, which sends a request to the Web Server to get one HTML webpage.
Server Process
This is the process which takes a request from the cpents. After getting a request from the cpent, this process will perform the required processing, gather the requested information, and send it to the requestor cpent. Once done, it becomes ready to serve another cpent. Server processes are always alert and ready to serve incoming requests.
Example − Web Server keeps waiting for requests from Internet Browsers and as soon as it gets any request from a browser, it picks up a requested HTML page and sends it back to that Browser.
Note that the cpent needs to know the address of the server, but the server does not need to know the address or even the existence of the cpent prior to the connection being estabpshed. Once a connection is estabpshed, both sides can send and receive information.
2-tier and 3-tier architectures
There are two types of cpent-server architectures −
2-tier architecture − In this architecture, the cpent directly interacts with the server. This type of architecture may have some security holes and performance problems. Internet Explorer and Web Server work on two-tier architecture. Here security problems are resolved using Secure Socket Layer (SSL).
3-tier architectures − In this architecture, one more software sits in between the cpent and the server. This middle software is called ‘middleware’. Middleware are used to perform all the security checks and load balancing in case of heavy load. A middleware takes all requests from the cpent and after performing the required authentication, it passes that request to the server. Then the server does the required processing and sends the response back to the middleware and finally the middleware passes this response back to the cpent. If you want to implement a 3-tier architecture, then you can keep any middleware pke Web Logic or WebSphere software in between your Web Server and Web Browser.
Types of Server
There are two types of servers you can have −
Iterative Server − This is the simplest form of server where a server process serves one cpent and after completing the first request, it takes request from another cpent. Meanwhile, another cpent keeps waiting.
Concurrent Servers − This type of server runs multiple concurrent processes to serve many requests at a time because one process may take longer and another cpent cannot wait for so long. The simplest way to write a concurrent server under Unix is to fork a child process to handle each cpent separately.
How to Make Cpent
The system calls for estabpshing a connection are somewhat different for the cpent and the server, but both involve the basic construct of a socket. Both the processes estabpsh their own sockets.
The steps involved in estabpshing a socket on the cpent side are as follows −
Create a socket with the socket() system call.
Connect the socket to the address of the server using the connect() system call.
Send and receive data. There are a number of ways to do this, but the simplest way is to use the read() and write() system calls.
How to make a Server
The steps involved in estabpshing a socket on the server side are as follows −
Create a socket with the socket() system call.
Bind the socket to an address using the bind() system call. For a server socket on the Internet, an address consists of a port number on the host machine.
Listen for connections with the psten() system call.
Accept a connection with the accept() system call. This call typically blocks the connection until a cpent connects with the server.
Send and receive data using the read() and write() system calls.
Cpent and Server Interaction
Following is the diagram showing the complete Cpent and Server interaction −
Advertisements