Key words about communication udp/(TCP/IP)/ipc/rpc/.net remoting/webservice/wcf/http series

Source: Internet
Author: User
Tags message queue wsdl

The relationship between OSI layer seven and TCP/IP layer four

1.1 OSI introduces the concepts of services, interfaces, protocols, and hierarchies, and TCP/IP builds the TCP/IP model using these concepts from OSI.

1.2 OSI first has the model, then has the agreement, first has the standard, then carries on the practice, but the TCP/IP is opposite, first has the protocol and the application to propose the model again, and is the reference OSI model.

1.3 OSI is a theoretical model, and TCP/IP has been widely used as a de facto standard for network interconnection.

Tcp:transmission Control Protocol Transmission Protocol

Udp:user Data Protocol User Datagram Protocol

OSI Layer Seven Network model

TCP/IP four-layer conceptual model

Corresponding network protocol

Application Layer (application)

Application Layer

HTTP, TFTP, FTP, NFS, WAIS, SMTP

Presentation Layer (Presentation)

Telnet, Rlogin, SNMP, Gopher

Conversation Layer (session)

SMTP, DNS

Transport Layer (Transport)

Transport Layer

TCP, UDP

Networking Layer (Network)

Network layer

IP, ICMP, ARP, RARP, AKP, UUCP

Data Link Layer

Data Link Layer

FDDI, Ethernet, Arpanet, PDN, SLIP, PPP

Physical Layer (physical)

IEEE 802.1A, IEEE 802.2 to IEEE 802.11

-----------------------------------------------cut--------------------------------------------.

Software developers are generally in the application layer !

Common TCP UDP HTTP that is used

The socket is the TCP/IP protocol API TCP is the media of the data, the socket is the media of TCP. Check the RFC document, the socket is RFC147, the update Time is 1971. TCP is RFC793 and the update Time is 1981. The socket appears on the ARPA network. It should be said that TCP is a communication protocol on the socket. http://bbs.csdn.net/topics/320251688 http://www.cnblogs.com/riacool/ Archive/2010/12/14/1905404.html the relationship between TCP/IP and sockets

To write a network program, you have to use a socket, which is what programmers know. Also, during the interview, we will ask the other party will not socket programming? Generally speaking, many people will say, socket programming is basically listen,accept and send,write, and so on a few basic operations. Yes, as with common file operations, you must know when you write.

For the network programming, we also say that TCP/IP, it seems that other network protocols no longer exist. For TCP/IP, we also know that TCP and UDP, the former can guarantee the correct and reliable data, the latter allows data loss. Finally, we also know that you must know the IP address and port number of the other person before establishing the connection. In addition to this, ordinary programmers will not know too much, many times this knowledge is enough. At most, when a service program is written, multithreading is used to handle concurrent access.

From: 52288112

From: https://www.cnblogs.com/LUO77/p/5801977.html

Comparison between IPC interprocess communication and TCP

IPC, full name inter process communication i.e. interprocess communication, two processes on the same machine are used IPC, not across physical machines. IPC includes shared memory, queue, signal volume and other methods, due to the high efficiency of the IPC communication, so a large number of Unix under the software are used IPC communication, such as Oracle.

TCP/IP, full name transmission Control protocol/internet Protocol is the Transmission Protocol/network Protocol, TCP/IP can communicate in two processes between the same machine or two physical machines or different operating platforms. Standard IPC/IP communication process: On Host 1, the application layer transmits a string of application data to the transport layer, and the transport Layer truncates the application layer's data stream into a packet, and the TCP header forms a TCP segment to send to the network layer, and the IP header including the source and destination host 2 IP address is added to the TCP segment at the network layer. An IP packet is generated and the IP packet is sent to the link layer, and the link layer is loaded with an IP packet in the data portion of its Mac frame, plus the MAC address and frame header of the source, destination host 2, and the Mac frame is sent to the destination host 2 or IP router based on its destination MAC address. In the destination host 2, the link layer removes the frame header of the Mac frame and sends the IP packet to the network layer; The network layer checks the IP header, and if the header is inconsistent with the computed result, the IP packet is discarded, and if the checksum is consistent with the computed result, the IP header is removed and the TCP segment is sent to the transport layer; , determine if the TCP packet is correct, and then check the TCP header data. If correct, then to the source Host 1 to confirm the information, if not correct or drop the packet, the source host 1 is required to re-send information, in the destination host 2, the transport layer stripped of the TCP header, the sorted sequence of packets composed of application data flow to the application. In this way, the host 2 receives a byte stream from the source host 1, as if it were directly receiving a byte stream from the source host 1.

If two processes are on the same machine and on the same operating platform, either IPC or TCI/IP can be selected for two communication methods, but the IPC is more efficient than TCP/IP. Using IPC communication, Process 1 directly to the communication packet Process 2, the use of TCP/IP communication, Process 1 will first send the communication packet "Lo" is the local loop interface, through "Lo" and then send the communication packet to process 2.

If two processes on different physical machines or in different operating platforms, then can not use the IPC, at this time with TCP/IP communication, process 1 to send the communication packet to the physical network card 1, physical network card 1 through the network cable to the process 2 is the machine's physical network card 2, Nic 2 and then send the communication packet to process 2.

Several realization ways of IPC

The way the process communicates pipe (pipe):

The pipeline consists of three types:

    • Common pipe pipes: there are usually two kinds of restrictions, one is simplex, only one-way transmission, and second, can only be used between father and son or sibling processes.
    • Stream pipeline S_pipe: Remove the first restriction, half-duplex, can only be used between parent-child or sibling processes and may be transmitted in both directions.
    • Named pipes: name_pipe: In addition to the second limitation, you can communicate between many unrelated processes.
Signal Volume (Semophore):
    • A semaphore is a counter that can be used to control access to shared resources by multiple processes. It is often used as a locking mechanism to prevent a process from accessing the shared resource while other processes are accessing the resource. Therefore, it is primarily used as a means of synchronization between processes and between different threads within the same process.
Message Queuing (Messages queue):
    • Message Queuing is a linked list of messages, stored in the kernel and identified by message queue identifiers. Message Queuing overcomes the disadvantages of less signal transmission information, only unformatted byte stream, and limited buffer size.
Signal (sinal):
    • A signal is a more sophisticated form of communication that notifies the receiving process that an event has occurred.
Shared Memory:
    • Shared memory is the mapping of memory that can be accessed by other processes, which is created by a process, but can be accessed by multiple processes. Shared memory is the fastest IPC approach and is specifically designed for low-efficiency operation of other interprocess communication modes. It is often used with other communication mechanisms, such as signal two, to achieve synchronization and communication between processes.
Socket (SOCKET):
    • The socket is also an inter-process communication mechanism, and unlike other communication mechanisms, it can be used for process communication between different machines.

Reference: https://www.linuxidc.com/Linux/2016-10/136542.htm

Rpc:

RPC Service

The RPC service is described in three ways: RPC schema, synchronous asynchronous invocation, and popular RPC framework.

RPC Schema

Let's talk about the basic architecture of the RPC service. Allow me to steal a picture with shame. We can clearly see that a complete RPC architecture contains four core components, namely the Client, the server,client stub, and the Server stub, which you can understand as stubs. Say these components separately:

    • Client, the caller of the service.
    • Service-side (Server), a true service provider.
    • The client stub, which stores the address message on the server, then packages the client's request parameters into a network message and sends it to the service provider remotely over the network.
    • A service-side stub that receives a message sent by the client, unpacking the message, and calling the local method.

RPC is mainly used in large enterprises, because large enterprises inside a wide range of systems, business lines complex, and efficiency advantages of a very important piece, this time the advantages of RPC is more obvious. This is done in real-world development, and projects are typically managed using MAVEN. For example, we have a system service for processing orders, declare all of its interfaces (this is specifically referred to in Java interface ), and then package the entire project as a jar package, the server side to introduce this two-party library, and then implement the corresponding functions, The client side also needs only to introduce this two-party library to call. Why did you do this? Mainly to reduce the size of the client side of the jar package, because each time the package jar is released, too many packages will always affect efficiency. In addition, the client and the server are decoupled to improve the portability of the code.

Synchronous calls and asynchronous calls

What is a synchronous call? What is an asynchronous call? 同步调用is that the client waits for the call to finish and returns the result. 异步调用is that the client does not wait for the call execution to complete the return result, but can still receive a notification of the return result through the callback function. If the client does not care about the result, it can become a one-way call. This process is a bit like Java callable and runnable interface, when we execute asynchronously, if we need to know the result of execution, we can use the callable interface, and can Future get the result information of asynchronous execution through the class. If you do not care about the results of the implementation, the direct use of the runnable interface can be, because it does not return the results, of course, it callable is also possible, we do not have to get Future on it.

The popular RPC framework

The current popular open source RPC framework is still much more. Here are three ways to focus:

    1. GRPC is Google's latest open source software, based on the newest HTTP2.0 protocol and supports many common programming languages. We know that HTTP2.0 is a binary-based version of the HTTP protocol upgrade that is currently being supported by major browsers. This RPC framework is implemented based on the HTTP protocol, and the underlying use of the Netty framework is supported.
    2. Thrift is an open source project for Facebook, primarily a cross-language service development framework. It has a code generator that automatically generates a service code framework for the IDL definition file it defines. As long as the user two times before the development of the line, for the underlying RPC communication, etc. are transparent. However, this has a certain cost for the user to learn the characteristics of specific domain language.
    3. Dubbo is an extremely well-known RPC framework for Alibaba Group's Open source, which is widely used in many Internet companies and enterprise applications. Both the Protocol and the serialization framework are pluggable and distinctive. The same remote interface is based on Java Interface and is easy to develop with the spring framework. It can be conveniently packaged into a single file, run independently, and be consistent with the current microservices concept.

偷偷告诉你The group has not how to use Dubbo, now with more than the name of HSF, aka "Good comfortable". There may be open source behind, and we'll wait and see.

HTTP Service

In fact, a long time ago, my model for enterprise development has been defined as the development of HTTP interfaces, which is what we often call the RESTful style of service interface. Indeed, for a small number of interfaces, systems and systems with less interaction, the solution of the early days of information is often used in a means of communication, the advantages are simple, direct, easy to develop. Transfer using the ready-made HTTP protocol. We remember before the undergraduate internship in the background development of the company, the main is to develop the interface, but also to write a large portion of the interface document, strictly indicate what is the input and output? Make clear the request method for each interface, as well as the things to be aware of when requesting parameters. For example, the following:
POST http://www.httpexample.com/restful/buyer/info/share
The interface may return a JSON string or an XML document. The client then processes the returned information so that it can be developed in a relatively rapid manner. But for large enterprises, the internal subsystem is more, the interface is very large, the benefits of the RPC framework is shown, the first is the long link, do not have to each communication like HTTP to 3 times to shake a handshake or something, reduce the network overhead; Next is the RPC framework generally has a registration center, has a wealth of monitoring and management , release, downline interface, dynamic expansion, etc., is a non-aware, unified operation for the caller.

Summarize

The RPC service and HTTP service still have a lot of different points, in general, the RPC service is mainly for large enterprises, and the HTTP service is mainly for small enterprises, because RPC is more efficient, and HTTP service development iterations will be faster. In short, the choice of what kind of framework is not based on what is popular in the market, but the entire project to be fully evaluated, so that in careful comparison of the two development frameworks for the overall impact of the project, and finally decide what is the most suitable for this project. Be sure not to use RPC for each project with RPC, but to adapt to local conditions, specific analysis.

. NET Remoting/webservice/wcf/http

Remoting and Web service are important technologies in. NET that can be used for distributed system development, but if you have a different platform, you can choose only Web service, but if it is the same platform, you have the choice. In the end, there is also the consideration of the efficiency of the visit, while in the remoting there are three channels HTTP,TCP,IPC, and they are different. The HTTP channel has the advantage over the firewall, and the TCP channel often communicates in the local area network, which is much faster than HTTP; the IPC channel is used for interprocess communication of the same machine, the communication does not occupy network resources, and the speed is much faster than TCP. In order to actually compare the actual access speed of these four, I wrote a small program with the test. The implementation of this program is simple to access the same object (equivalent to the business layer in the actual project) using remoting three channels and Web Service, and this object implements the time to return the system. It's so simple. If you are not familiar with remoting and Web service, you can also use this example to familiarize yourself with the differences in the way remoting three channels are written and the invocation of Web service.

Here is the program run interface, I use the minimum time measurement in. NET: Ticks (which may be difficult to measure in milliseconds on this computer), to test the time of each invocation and to compare the speed of the access by a number of times the average time is measured. By testing, you can see how fast they have access to the four: Ipc>tcp>http>web Service. (In fact, the remoting HTTP channel and Web service access speed has yet to be compared, with the test of the host has a certain relationship, in my office, a computer as if the Web service access faster than the HTTP channel), you can test it yourself, Or to study a better method.

Related code:

  1//using HTTP Channel 2 public void http () 3 {4 Stopwatch Stopwatch = new Stopwatch ();  5 Stopwatch.start ();  6 MyObject MYOBJ = (MyObject) Activator.GetObject (typeof (MyObject), "Http://localhost:9001/MyObject");  7 Myobj.getservertime ();  8 Stopwatch.stop (); 9 LsbHttp.Items.Add (stopwatch.elapsedticks);         10} 11//Use TCP channel-public void TCP () Stopwatch Stopwatch = new Stopwatch (); 15 Stopwatch.start (); MyObject MYOBJ = (MyObject) Activator.GetObject (typeof (MyObject), "Tcp://localhost:9002/myobject"); Myobj.getservertime (); Stopwatch.stop (); LSBTCP.ITEMS.ADD (stopwatch.elapsedticks); 20} 21//Use IPC channel on public void Ipc () Stopwatch Stopwatch = new Stopwatch (); Watch.start (); MyObject MYOBJ = (MyObject) Activator.GetObject (typeof (MyObject), "Ipc://myhost/myobject"); Myobj.getservertime (); StopwAtch. Stop (); LSBIPC.ITEMS.ADD (stopwatch.elapsedticks); 30} 31 32//Access Web Service public void WebService () {Stopwatch Stopwatch = new STOPWATC H (); Stopwatch.start (); Notoginseng localhost. Service ws = new localhost. Service (); WS. GetServerTime (); Stopwatch.stop (); LSBWEB.ITEMS.ADD (stopwatch.elapsedticks); The Btnhttp_click (object sender, EventArgs e) is {Http (); te void Btntcp_click (object sender, EventArgs e), {TCP () (), and $ btnwebservice_c private void Lick (object sender, EventArgs e): {WebService (); +--------Btnipc_click (Object se  NDEr, EventArgs E) (+) (60} 61 62//Start test for the private void Btnstat_click (object sender, EventArgs e): {Int32 times = Int. Parse (Txttimes.text); Int64 Sum = 0; Double ave=0; LSbHttp.Items.Clear (); LsbIpc.Items.Clear (); LsbTcp.Items.Clear (); LsbWeb.Items.Clear ();         for (Int32 i = 0; I < times; i++)----Http (); TCP (); WebService (); 79} 80//Calculates the average time of the Bayi for (Int32 i=0;i<times;i++) ($ + = int). Parse (Lsbhttp.items[i]. ToString ()); (+) = Sum/times; Txthttp.text = Ave.tostring (); Sum = 0; Int32 i = 0; I < times; i++) (+) Parse (Lsbtcp.items[i]. ToString ()); The "Sum/times" of the Ave =; 94 Txttcp.text = Ave.tostring (); Sum = 0; Int32 i = 0; I < times; i++) 98 {Sum + = Int. Parse (Lsbweb.items[i].        ToString ());}101 Ave = sum/times;102 Txtwebservice.text = ave.tostring (); 103 104 Sum = 0;105 for (Int32 i = 0; I < times; i++) 106 {107 SUm + = Int. Parse (Lsbipc.items[i]. ToString ()); 108}109 Ave = sum/times;110 Txtipc.text = ave.tostring (); 111}112 HttpChannel H Ttpchannel = new HttpChannel (9001); 113 ChannelServices.RegisterChannel (httpchannel,false); TcpChannel TcpChannel = new TcpChannel (9002); ChannelServices.RegisterChannel (Tcpchannel,false); 117 118 IpcChannel IP Cchannel = new IpcChannel ("MyHost"); 119 ChannelServices.RegisterChannel (Ipcchannel,false); 121 Remotingcon Figuration. RegisterWellKnownServiceType (typeof (RemoteObject. MyObject), "MyObject", WellKnownObjectMode.SingleCall); 122 console.readline ();

WebService

C # calls WebService instances and development

First, the basic concept

Web service, also known as XML Web service WebService , is a lightweight, independent communication technology that can receive requests passed from the Internet or other systems on the intranet. is: Software services provided through SOAP on the web, described using WSDL files, and registered through UDDI. The simple understanding is thatWebService is the function that is placed on the server, which can be called by everyone, and then return information. Google, for example, has a Web service that you can call to make it easy to do a search site. Just like calling a function, passing in a number of parameters (such as keywords, character encodings, and so on) can then return the content retrieved by Google (returning a string). which

Soap: Simple Object access Protocol protocol. is the communication protocol for XML WEB Service. When a user finds your WSDL description document through UDDI, he can invoke one or more of the actions in the Web service that you set up by soap. SOAP is a specification for calling methods in the form of XML documents that can support different underlying interfaces, such as HTTP (S) or SMTP.

WSDL: (Web Services Description Language) A WSDL file is an XML document that describes a set of SOAP messages and how to exchange them. In most cases, it is automatically generated and used by the software.

UDDI (Universal Description, Discovery, and integration) is a new project primarily for Web service providers and users. Before a user can invoke a Web service, it is important to determine which business methods are included in the service, to find the called interface definition, and to prepare the software on the server side, and UDDI is a mechanism to guide the system through the description document to find the appropriate service. UDDI uses the SOAP message mechanism (standard xml/http) to publish, edit, browse, and find registration information. It uses XML format to encapsulate various types of data and send it to the registry or to the registry to return the required data.

Reference: Https://www.cnblogs.com/peterpc/p/4628441.html WCF 1. What is WCF?

From the point of view of WCF, it is included in. NET 3.0 (also including. NET 3.5). We note that the only difference between. NET 3.0 and. NET 2.0 is that. NET 3.0 contains WCF, WPF, WF (or CardSpace). Therefore, we think that WCF is part of the. NET Framework and does not seem to be too much. Crucially, WCF does not exist separately from the. NET Framework (but not WCF clients can invoke WCF services), so while WCF is specifically designed to address the development needs of SOA solutions, it is not a framework like spring, struts, Nor is it a container or server like EJB. Microsoft really conforms to the SOA Enterprise Application Server role, and I think it should be BizTalk Server.

Strictly speaking, WCF is a set of specialized classes dedicated to service customization, publishing and running, and messaging and processing, known as the "Class library." These classes are organized in a way that works together and provides a unified programming model for developers. WCF is special because it has to deal with the scene and the ordinary. NET class library, it is mainly used to deal with the transmission and processing of messages between process and machine, and it introduces the design idea of SOA, which is advertised and run in the way of service, so as to facilitate the client to call the service across process and machine. In fact, WCF is the integrator of Microsoft's programming technology for distributed processing, which integrates DCOM, Remoting, Web Service, WSE, and MSMQ to reduce the learning curve of distributed system developers and unify development standards.

WCF is also different from other class libraries in that WCF fully embodies the concept of the runtime environment. For developers who used WCF earlier, it might be possible to know that if you were to develop WCF under. NET 2.0, you would also need to download a runtime Component version 3.0 specifically, which contains content such as WCF, WF, and so on. There is a consistent concept of so-called "hosting" in. NET, and the entire. NET Framework (or CLR) can be thought of as a large host, just like a Java virtual machine. Because WCF has a special need for services, it needs to publish and run the service for the server, and for the client, it needs to invoke the service, and for the developer it is necessary to write code that defines, publishes, runs, and invokes the service. Services can only be run on a specific host, such as console application processes, Windows or Web application processes, or Windows service processes, or the most common IIS hosts. Inside the host, the channel stack is encapsulated, which also contains the processing of protocols, encodings, message transmissions, and proxies. At the top of the channel layer, you also provide an advanced runtime for the application developer. Reference: http://www.cnblogs.com/wayfarer/archive/2008/04/15/1153775.html http, HTTPS system: WebService WCF also supports WebForm MVCWEBAPI In actual projects, different strategies are used depending on the scenario. End: The Times are progressing ...

Key words about communication udp/(TCP/IP)/ipc/rpc/.net remoting/webservice/wcf/http series

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.