RJ博客

Socket与WebService比较

本文目录



一 区别


1.Socket是一种协议,采用Tcp或udp协议通信。Tcp、udp属于网络层,上边各层的应用都需要我们自己实现,例如端口的定义,数据包的定义,数据包的加密解密等。


2.WebService是一种服务,采用HTTP协议通信,Soap作为数据格式。HTTP协议属于应用层,通过服务器才可以发布,这样内部定义的端口,数据包,加解密都做好了,可以直接使用。WebService内部数据格式为xml格式、由于基于HTTP协议,所以可以不受防火墙的影响。


二 优缺点


1.适用对象

WebService用HTTP,是单次通信,只连接一次;Socket是可以面向连接和不面向连接的。

如果是简单的只发送一条数据,而且是隔很长一段时间才发送一次信息,那么建议用HTTP。如果是想做实时的信息交互,那么最好用Socket,因为Socket能够建立起来一个连接通路,并且监听连接后的Socket发送的数据。

一般较小的项目,数据量较少的项目,用WebService足够了,Socket的工作量投入和回报不成正比,但对于数据量较大的项目,或者对实时性要求很高的项目,像手游之类的,用WebService是不现实的。


2.速度:

WebService 是建立在 HTTP 基础之上的,而HTTP 是建立在 TCP 基础上的。也就是说 WebService 在 TCP 基础上包装了两层!

但是,直接使用 TCP Socket 的话速度是快了,但是出错的几率,以及开发难度成数倍地增加了。Socket 通信的话,你还得自己设计通信协议,光这点就很复杂。 


3.趋势:

现在的大趋势已经逐渐走向SOA架构了,所以肯定是WebService越来越受欢迎,在网络上跨平台调用你的服务就像你在程序里调用底层封装好的一个API方法一样简单。如果是基于Socket,别人想要调用你的服务,还得专门写一个支持你这个Socket接口的Adapter。 


网络七层协议从低到高:
1、物理层(Physical Layer)
2、数据链路层(Data Link Layer)
3、网络层(Network Layer)
4、传输层(Transport Layer)
5、会话层(Session Layer)
6、表示层(Presentation Layer)
7、应用层(Application Layer)




参考文献: http://blog.163.com/lively_caicai/blog/static/2092171222012814113047728

原文地址: http://blog.csdn.net/finallylly/article/details/44887923

作者: finallylly


相关推荐

发表评论

  • 欢迎评论

  • Hello, It is with sad regret to inform you that BestLocalData.com is shutting down. We have made all our databases for sale for a once-off price. Visit our website to get the best bargain of your life. BestLocalData.com Regards, Etta

  • Hey, It was nice speaking to you the other day, this is the service I was telling you about that helped us boost our ROI almost 2000% Its a company called Lifemail.studio sorry it took so long to get back to you. They allow you to send any email doesn't matter what. We dealt with a guy named Michael, he was friendly and got us setup really quickly. Regards, Tim

  • Hey, It was nice speaking to you the other day, this is the service I was telling you about that helped us boost our ROI almost 2000% Its a company called Lifemail.studio sorry it took so long to get back to you. They allow you to send any email doesn't matter what. We dealt with a guy named Michael, he was friendly and got us setup really quickly. Regards, Julissa

  • SendBulkMails.com allows you to reach out to clients via cold email marketing. - 1Mil emails starter package - Dedicated IP and Domain Included - Detailed statistical reports (delivery, bounce, clicks etc.) - Quick and easy setup with extended support at no extra cost. - Cancel anytime! SendBulkMails.com

  • SendBulkMails.com allows you to reach out to clients via cold email marketing. - 1Mil emails starter package - Dedicated IP and Domain Included - Detailed statistical reports (delivery, bounce, clicks etc.) - Quick and easy setup with extended support at no extra cost. - Cancel anytime! SendBulkMails.com

  • QGWRYM0X20Z1RJSWXF www.google.com

  • Hey there nearby.wang, Do you always seat with your computer working for a long time? Or you see yourself in a position where you always focus on something for a long time, like computer screens or Television? Well, if you are in this category, you must have had experiences with neck pain. Yes, I know, that can be very painful. Fortunately, Here’s an instant solution for you my friend – Smart Electric Neck Massager. This is an electric massager which when hung around your neck can give you the same relief feeling you get from a chiropractor. It’s smart, portable, and affordable. Right now, it’s available at neckbc.com Online Store. We are offering 50% off on our product. The procurement process is very simple, just hit the buy button and we get it shipped right off to you. To know more about this special device, you can visit here neckbc.com . Why don’t you say goodbye to that neck pain today? We are expecting your order right away!

  • 666