Distributed software Architecture style (C/S,B/S)

Source: Internet
Author: User

Distributed Software Architecture Style

1, three layer C/s structure

2, three layer B/s structure

Learn more about software architecture

Three-layer C/s structure (3-tier C/S Architecture)

§ Layer 1th: User Interface gui-Presentation Layer--Client

§ Layer 2nd: Business logic-Functional Layer-Application server

§ Layer 3rd: Database-Data tier-database server

Basic components:

– Database server

? The database that holds the data and the business logic responsible for data processing;

– Application Server

? Business logic: the processing of data;

– Client application

? GUI: User interface

§ Connectors: Call-back mechanism or implicit invocation mechanism via the network

– Client? à application server: The client sends a request to the application server and receives the returned result.

– Application server? à data server: The application server sends requests to the data server and receives the returned results.

Presentation layer:

§ The user interface part of the application, which is responsible for the dialogue between the user and the application;

§ Check the data entered by the user from the keyboard, display the data of the application output, and examine the contents of the data in the form and value range, excluding the processing logic of the business itself.

§ In order to enable users to operate intuitively, the GUI is usually used, which is easy to operate and easy to learn and use.

§ In the change, only need to rewrite the display control and data inspection procedures, without affecting the other layers;

§ does not contain or contain part of the business logic.

function Layer:

§ The main body of the application system, including most of the business processing logic (usually in the form of business components, such as javabean/ejb/com, etc.); For example, to calculate the contract amount at the same time as the order is made, configure the data in a fixed format, and print the order contract.

§ Obtains the user's input data from the presentation layer and processes it;

§ The process needs to fetch data from the data layer or update data to the data layer;

§ Processing results are returned to the presentation layer.

§ When the user retrieves the data, it tries to transfer the information about the retrieval request to the functional layer at one time, and the result data processed by the functional layer is transmitted to the presentation layer at once.

Typically, the feature layer includes features that confirm user access to apps and databases, and the ability to log systems to process logs.

Data layer:

§ Database management System DMBS, responsible for the management of database data read and write;

§ Accept the function Layer data query request, execute the request, and return the query result to the function layer;

§ Accepts data access requests from the functional layer and writes the data to the database, and the execution results of the request are returned to the functional layer.

§ The database management system must be able to quickly perform large amounts of data updates and retrieval. Now the mainstream is the relational database management system, therefore, the general transfer from the functional layer to the data layer of the requirements of most of the use of SQL language.

Advantages:

§ In the case of a large number of users, the three-tier C/s structure will greatly improve performance and flexibility (usually can support hundreds of concurrent users, through the cluster up to tens of thousands of concurrent users);

§ Allows the function of the three-layer structure to be logically maintained relative independence, can improve the maintainability and extensibility of the system and software--ui, BL, DB can be reused separately

Allows for more flexible and efficient use of the appropriate platform and hardware system, so that

The processing load capacity and processing characteristics are adapted to the structure of the three layers clearly, and these platforms and components can have good scalability and openness.

Each layer of the application can be developed in parallel and can be selected for the most appropriate development platform and development language.

§ effectively separated from the presentation layer and the data layer using functional layer, the unauthorized users can not bypass the functional layer and illegal access to the data layer, for strict security management laid a solid foundation.

§ Porting Legacy systems (legacy systems) to the three-tier C/s will be very easy;

Disadvantages:

§ Three layer C/s structure of the communication efficiency between each layer if not high, even if the hardware assigned to each layer is very strong, it as a whole can not achieve the required performance.

§ Design must carefully consider the three-layer communication method, communication frequency and data volume, which and improve the independence of each layer is the three-layer C/s structure of the key issue-the inherent shortcomings of layered style.

Program:

(1) server-side program Tcpserver.java

Import java.io.*;

Import java.net.*;

public class tcpserver{

publicstatic final int port=8888;

publicstatic void Main (string[] args) throws ioexception{

Establish ServerSocket

ServerSocket s=new ServerSocket (PORT);

System.out.println ("ServerSocket:" +s);

try{

/* Program blocked, waiting for connection. That is, until a client request arrives, the program can continue to execute */

Socket ss=s.accept ();

System.out.println ("socketaccept:" +ss);

try {

The connection is successful and the corresponding I/O data stream is established

DataInputStream Dis=newdatainputstream (Ss.getinputstream ());

DataOutputStream dos=new DataOutputStream (Ss.getoutputstream ());

In the loop, communicate with the client

while (true) {

String Str=dis.readutf (); Read data from the client

if (Str.equals ("End")) break; When the end is read, the program terminates

System.out.println (str);

Dos.writeutf ("Echoing:" +str); Write data to the client machine

}

Dos.close ();

Dis.close ();

}finally{

Ss.close ();

}

}finally{

S.close ();

}

}

}

The server-side operation results are:

SERVERSOCKET:SERVERSOCKET[ADDR=0.0.0.0/0.0.0.0,PORT=0,LOCALPORT=8888]

Socket accept:socket[addr=/127.0.0.1,port=7312,localport=8888]

Tests: 0

Tests: 1

Tests: 2

Tests: 3

Tests: 4

Tests: 5

(2) client-side program Tcpclient.java

Import java.io.*;

Import java.net.*;

public class tcpclient{

public static Voidmain (string[] args) throws ioexception{

To set up a socket, the server "listens" at port 8888 of this machine

Socket ss=newsocket ("127.0.0.1", 8888);

System.out.println ("Socket:" +ss);

try{

Socket established successfully, establish I/O stream for communication

Datainputstreamdis=new DataInputStream (Ss.getinputstream ());

Dataoutputstreamdos=new DataOutputStream (Ss.getoutputstream ());

for (int i=0;i<6;i++) {

Dos.writeutf ("Test:" +i); Sending data to the server

Dos.flush (); Flush the output buffer for immediate dispatch

System.out.println (Dis.readutf ()); Data output to be received from the server

}

Dos.writeutf ("End"); Send a termination flag to the server

Dos.flush (); Flush the output buffer for immediate dispatch

Dos.close ();

Dis.close ();

}finally{

Ss.close ();

}

}

}

b/S three layer structure:

Browser/server (b/s) is a three-layer C/s style of implementation of a way

– Presentation layer: Browser

– Logic layer:? Web server? Application Server

– Data tier: Database server

Basic components:

– Database server? The database that holds the data and the business logic responsible for data processing;

– Web server/application server? Business logic: processing the data; The client application is stored on the Web server as a Web page;

Browser? Type the appropriate URL in the browser on the client

Connectors: Call-back mechanism or implicit invocation mechanism via the network

– Browser? àweb Server/Application server: The browser sends a request to the Web server/application server and receives the returned results.

– Web server/application server? à data server: The Web server/application server sends requests to the data server and receives the returned results.

Advantages:

Based on B/S architecture software, system installation, modification and maintenance of the full

In server-side resolution, system maintenance costs are low:

– The client has no business logic, and when using the system, the user only needs a browser to run all the modules, really achieve the "0 client" function, it is easy to automatically upgrade at run time.

– Good flexibility and scalability: For situations where the environment and application conditions are constantly changing, the goal can be achieved as long as the corresponding changes are implemented for the business logic layer.

The §B/S architecture also provides the most realistic open foundation for online, networked, and unified services for heterogeneous machines, heterogeneous networks, and heterogeneous application services.

§ Better security: In this structure, the client application does not have direct access to the data, and the application server can control not only which data is changed and accessed, but also how the data is changed and accessed.

§ Three-tier mode is a true "thin client" with high stability, ductility, and execution efficiency.

§ Three-tier mode can centralize services to manage and serve clients uniformly, thus providing good fault tolerance and load balancing capability.

Expanded the functional coverage of the organization's computer application system to

Leverage various resources on the network, while maintaining the workload of the application

Also greatly reduced

Before the –B/S structure appeared, the functional coverage of the management information system was mainly group

Woven interior.

The –B/S structure "0 client" approach makes it possible for the organization's suppliers and customers (these suppliers and customers, potentially unknown) to easily become clients of the management information system, and to query organization-related information within a limited range of functionality, Complete the data exchange and processing of various business dealings with the organization.

The combination of computer application system and Internet in §B/S structure makes it possible to implement some new enterprise computer applications (e-commerce, customer relationship Management) recently.

Disadvantages:

§ The client browser exchanges data in a synchronous request/response mode and refreshes the page every time the server is requested;

§ By the HTTP protocol "text-based data exchange" restrictions, in the data query and other response speed, is much lower than the C/s system structure;

§ Data submission generally in the page, the data dynamic interactivity is not strong, not conducive to online transaction processing (OLTP) applications;

§ Limited by the ability to express HTML, difficult to support complex GUI (such as reports, etc.).

Program:

Front Interface code:

<%@ page language= "C #" autoeventwireup= "true" codebehind= "Default.aspx.cs" inherits= "Testweb1._default"%>

<! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.0transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<title> front screen </title>

<body>

<formid= "Form1" runat= "Server" >

<div>

</div>

</form>

</body>

Server code:

Using System;

Usingsystem.collections;

Usingsystem.configuration;

Using System.Data;

Using System.Linq;

Using System.Web;

usingSystem.Web.Security;

Using System.Web.UI;

UsingSystem.Web.UI.HtmlControls;

UsingSystem.Web.UI.WebControls;

UsingSystem.Web.UI.WebControls.WebParts;

Using System.Xml.Linq;

Namespace TestWeb1

{

public partial class _default:system.web.ui.page

    {

protected void Page_Load (Object Sender,eventargs e)

        {

String strselect = "Selectloginname,username from Users";

string STRCN [email protected] "server=.\sqlexpress;database=business;integrated security=true";

SqlDataAdapter ad = new SqlDataAdapter (SELECT_STR,STRCN);

DataSet ds = new DataSet ();

AD. Fill (ds, "MyTable");

DataTable dt = ds. Tables[0];

string str= "<ul>";

foreach (DataRow row in dt. Rows)

            {

str+= "<li>" +row[0]+ "| |" +row[1]+ "| |" +row[2]+ "<li>";

            }

str + = "</ul>";

Response.Write (str);

        }

    }

}

C/S+B/S Hybrid Architecture:

– Mixing principle One: the principle of "internal and external distinction"

– Mixing principle Two: the principle of "the search and change is different"

§ Mixing Principle one: "internal and external" principle:

– Direct access to the database server via local area network for enterprise internal users

? c/S structure;

? interactivity enhancement;

? The response speed of data query and modification is high;

– External users of the enterprise access the Web server/application server over the Internet

? b/S structure;

? Users do not directly access data, data security;

§ The disadvantage of "internal and external" model is that the external users of the enterprise modify and maintain the data, the speed is slow, more complex locks, the dynamic interaction of data is not strong

§ Mixing principle Two: the principle of "the search and Change is different":

– no matter where the user is located inside or outside the enterprise (local area network or the Internet), all operations (ADD, Delete, update) that require data to be updated (maintained and modified) are required to use the C/s structure;

– If you are only performing general query and browse operations (Read/query), use the B/s structure.

§ "Search and change" model embodies the common advantages of B/s architecture and C/s system structure.

§ However, because external users can directly connect to the database server through the Internet, enterprise data is easily exposed to external users, which poses a threat to data security.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Distributed software Architecture style (C/S,B/S)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.