The difference and comparison of socket and webservice

The difference and comparison of socket and webservice

 1. Socket is a protocol that uses tcp or udp protocol to communicate.

        Tcp and udp belong to the network layer, and the applications of each layer above need to be implemented by ourselves, such as the definition of ports, the definition of data packets, and the encryption and decryption of data packets.

2, webservice is a service, using HTTP protocol communication, Soap as the data format. HTTP is an application layer protocol based on TCP

        The HTTP protocol belongs to the application layer and can only be published through the server, so that the internally defined ports, data packets, and encryption and decryption are ready and can be used directly.

Webservice is based on the HTTP protocol, so it can use the existing very mature Web cluster to provide high load, compared to the socket is very difficult.

The WebService uses the HTTP-based SOAP protocol to transmit data, and the interface supports object-oriented. Finally, the WebService will serialize the object and transmit it through the stream.

The Socket interface transmits directly through streams and does not support object orientation.

 The seven-layer network protocol from low to high:

1. Physical Layer,

2. Data Link Layer,

3. Network Layer,

4. Transport Layer,

5. Session Layer,

6. Presentation Layer,

7. Application Layer

 

Webservice is generally divided into two types: http webservice and soap webservice, both of which are based on the http communication protocol and generally return data in xml format, so it can also be called xml webservice.

http webservice calls remote data services through the two methods of get post, which is suitable for the transmission of simple parameters (get directly brings parameters in the url); soap webservice transmits data through the soap protocol, soap is based on the xml standard, that is to say, it can be used xml structure data to transmit parameters, so that the parameter type can be very complex, and it is more convenient to process the xml data returned by remote.

其实soap协议也是基于http协议的.

webservice离不开web服务器(apache),web服务器是一个在公网上提供http通信的服务器.webservice 一般都建立在web服务器上,以供别人调用.

socket 是基于传输层的,http基于应用层,socket是一切通过端口通信的基础(包括http)

使用中,http常用于b/s通信,如web服务器就是用http做传输协议的,socket用于c/s(还有现在的富客户端),应用服务器中常用.socket穿防火墙有问题,而http几乎可以穿过任何防火墙(屏80的不多吧),socket通信的即时性比http好.

【Socket和WebService应用场景】

[ socket ]

适用于传输大数据量的数据。

缺点:由于传输的数据需要手动解析,socket通信的接口协议需要自定义,比如:自定义一种字符串拼接的格式,或者自定义的XML数据,自定义的麻烦之处在于接口调用方法和接口服务端需要相互讨论确定接口的协议内容,不方便。

优点:适合传输大数据量的数据。

 

[ WebService ]

WebService遵循标准的SOAP协议,SOAP协议的内容格式固定,SOAP协议传递的内容是XML数据,由于WebService是基于HTTP的,所以简单理解SOAP=HTTP+XML,因为WebService要经过两次序列化,所以导致其传输速度慢,适用于没有性能要求且数据传输量小的场景,推荐在公开接口上使用WebService。

以上是个人理解,如有纰漏,还望加以修正。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325871181&siteId=291194637