| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx

http协议和tcp协议的区别是什么

1
数据库 C/C++ 微信 Go http协议 30714 次浏览

很多朋友在现实生活中,不知道http协议 http://www.maiziedu.com/course/te/429-5568/ tcp协议的区别在哪里,今天,小编就来大家了解一下他们两者之间的区别,希望大家能跟着小编的思路具体来了解,下边就一起来看看吧!

当你需要准备做个安卓应用,服务端用golang写的,客户端语需要和服务端通信,这时就会想是用tcp好呢,还是用http协议呢?数据量挺大,哪个协议的效率更高呢,综合开发效率和传输效率?

HTTP 是应用层协议,TCP 是传输层协议(位于应用层之下),放在一起类比并不合适。
不过猜测楼主是想对比 标准 HTTP 协议” 还是 自定义的协议(基于 TCP Socket” 

一般来说,移动应用推荐使用 HTTP 协议,有很多优点:
HTTP 发展成熟
HTTP 几乎已经快成为一种通用的 Web 标准,Web ServicesRESTOpen APIOAuth 等等都是基于 HTTP 协议的。它已经不仅仅是 Hyper Text 的传输标准了,几乎所有数据的传输(多媒体、XMLJSON)都可以采用 HTTP
后台复用
因为很多应用,除了有移动端,还有Web端,甚至桌面端。
Web 版中前后台交互,无论是页面请求还是 AJAX 请求,都是采用标准 HTTP 协议。那么其他的客户端没有理由重新设计一套协议。
HTML 5 应用
现在不少移动产品都采用或者半采用 HTML 5 技术,那么和服务器的交互又回归到 AJAX 上。不用说,还是离不开 HTTP
但是也有一些局限性,比如以下场景就不适合 HTTP 协议:
实时数据推送
除了 iOS 开发提供有标准的 Apple 消息推送中心,其他移动产品可能还是要采用 Socket 长连接才能保证实时通讯。
比较常见的有很多即时通讯软件采用的 XMPP 协议。
流媒体
适用于音频播放、视频播放、语音会议等等,一般可能采用 RTMP 协议。

Http 是 TCP的上层协议,Http 是基于 TCP的,所以你用了HTTP,等同与你也在用TCP

所以,拿HttpTCP做优劣比较是一个不存在的问题。

当然,这问题提的很好,问的是相较基于tcp的自定义协议。

其实事实上,从宏观层面,已经自己回答了这个问题了。

为啥要自定义协议呢?很简单啊,http协议满足不了需求只好自定义协议啊。
也就是说,自定义协议可以满足很多http协议满足不了的需求啊。
那什么需求是http协议满足不了的呢?
这也很简单啊,可以查一下http协议的定义去看看它提供了什么样的包装和定义,落在它之外的就是满足不了的啊,要真的细说,那真是多了去了,比如:

例如:http是单工阻塞性质的协议,如果你需要一个全双工,无阻塞的双向传输,那http就满足不了

例如:http定义提供了很多种的请求方法,从getpost不一一列举了,但是你需要的请求应答模式和它定义的种种没有任何一种能够实现你需要的请求应答模式,你就需要自定义协议啊

例如:http定义自己的包头,你要是觉得传输效率极其重要,这样的包头太臃肿,你也需要自定义协议啊

要是http都能完全满足你的需求,那为啥要自定义协议呢?一个成熟的协议拿来就用明显是很好的选择啊。

现在REST一出,一改过去SOAP的复杂臃肿,HTTP协议本身一直也在扩充,因此适用的范围更广,更好用了。需要自定义协议的场景和需求也变少了。

如果要从微观层面去对比优劣,至少你得告诉你这个自定义协议是啥?
TCP上的自定义协议,那可是多如繁星,我拿哪个去做对比呢?

TCP长链接是一直连着不断开的。如果是TCP的话:
服务器端不是很好扩充,考验单台服务器的接入能力。服务器集群不是很好架设。
客户端,处理socket连接的那个线程要负责干各种事情,所有网络协议的逻辑集中在此,结构不太好搭。而http,结构就完全不同。

区别在于开发代价不同。http有大量现成架构,服务器,数据库,出了问题也不会全盘崩溃,调试代价小。
tcp必须自定义协议,然后自己处理;自己实现服务器,监听端口;遇到问题,自己打造一系列调试手段。自己动手造轮子,开发代价高了一个数量级。

最近正好在用http协议,是接手之前一个人做的,没办法代码重写,基于socket自定义协议对于移动开发快速迭代不合适,除非是一些比较底层的需求。估计像微信这样的也许会自定义协议,要不然带宽负荷太高。但是具体我也不了解。

所以能用http的地方,就不要用tcp。不过有的东西必须用tcp,比如网游,那是没办法的事情。

HTTP 协议的一个非常重要的优势在于穿越防火墙。
如果客户端到服务器之间有安全设备,那么可能唯一打开的端口就是TCP:80

移动端的开发更是如此,你不想用户整天抱怨说访问不到你的服务器吧。

以上就是小编为您讲解的http协议和tcp协议的区别了,相信以上的讲解,您一定对http协议和tcp协议两者都有一个明确的认识了。希望小编的讲解能给你带来帮助,同时,有什么需要还可请教我们的在线专家,祝大家进步。

 

34个答案

0

slot We have included all web slots camps. already here The best new online slots website of the year 2021, the only website to play slots for all game camps. From leading camps across the country, including pg slot, joker game, slotxo, live22 and many others

0

สล็อต789Online slots no minimum deposit-withdrawal with automation As fast as 8 seconds, including online slots from leading slot game camps

0

ฝาก20รับ100New arrivals, latest 2021 with special conditions 20 get 100

0

slot currently has online slot games. Comes in a new format with 3D images as slots online, direct websites and leading game camps such as PG SLOT JOKER GAME, new member registration,

0

เครดิตฟรีcurrently has online slot games. Comes in a new format with 3D images as slots online, direct websites and leading game camps such as PG SLOT JOKER GAME, new member registration, 100% bonus and many more slots

0

PG SLOTThe latest with a game system designed for direct pg slot players because the game format is very advanced, can play pg slot auto via ios and android systems, supports playing pg slots via mobile Deposit-withdraw automatically in just 8 seconds

0

ดาวน์โหลดjoker123 auto    Online slots, mobile phones, new online slots games, online slots that are the hottest in 2020, with low capital, can play.

0

ทางเข้า joker123   Top camp slots games Genuine license from PGSLOT game camp, online slots, direct web slot game service.

0

joker PG SLOT Game is a new and hot slot game that is gaining popularity right now, online slots, direct websites, not through agents.

0

เว็บตรง สล็อต PG SLOT online slots games A game that is popular with players all over the world right now. Your slots play will never be boring again.

0

The number 1 online slot game in Thailand, slot 888 online that includes the 888 slot game camp to play more than 300 games. Slot 888

0

Slot deposit 19 get the latest 100 2021 is a new pro slot and the strongest of the year Appealing to slot spinners with low budget who want to take money 19 baht to exchange money in the amount of 100 baht, which is considered very worthwhile because the promotion deposit 19 receives 100 unlimited withdrawals 19รับ100

0

A promotion that many people like and think that it is a worthwhile promotion. ฝาก20รับ100

0

Roma, the most popular online slots game of all time, roma slot 888, play free, online roma slot games. playing for real money Legendary online gambling game 2021 Roma Slots from famous gaming companies โรม่า

0

Direct web slots, not through agents online gambling games The most legendary casino game Stuck in one of the 5 most popular slot game camps. With more than 150 games to choose from, Joker Slot โจ๊กเกอร์

0

Direct web slots, not through agents online gambling games The most legendary casino game Stuck in one of the 5 most popular slot game camps. With more than 150 games to choose from, Joker Slot joker game

0

Direct web slots, not through agents online gambling games The most legendary casino game Stuck in one of the 5 most popular slot game camps. With more than 150 games to choose from, Joker Slot joker game

0

No deposit required is something that online gambling sites. free credit slots pg There is a reward for the members of the web. free credit slots no deposit will be able to play free slots all within the webเครดิตฟรี

0

No need to turn or call each other easily understood is a promotion, deposit 50, get 150 wallet, is another promotion that many people like and think that it is a worthwhile promotion. ฝาก50รับ150

0

The latest with a game system designed for direct pg slot players because the game format is very advanced, can play pg slot auto via ios and android systems, supports playing pg slots via mobile Deposit-withdraw automatically in just 8 seconds pg

1 2