问题描述
没有任何人有一个二进制协议就是一个很好的定义?什么是文本协议实际?如何做这些比较彼此在路上发送位条件怎么样?
does anyone have a good definition for what a binary protocol is? and what is a text protocol actually? how do these compare to each other in terms of bits sent on the wire?
这里是维基百科说,关于二进制协议:
here's what wikipedia says about binary protocols:
一个二进制协议是由机器读取,其目的或预期的协议,而不是一个人(http://en.wikipedia.org/wiki/Binary_protocol)
A binary protocol is a protocol which is intended or expected to be read by a machine rather than a human being (http://en.wikipedia.org/wiki/Binary_protocol)
哦,加油!
更清楚,如果我有JPG文件,怎么会是通过二进制协议,以及如何通过文本之一发送?在比特方面/字节上当然线路发送。
to be more clear, if I have jpg file how would that be sent through a binary protocol and how through a text one? in terms of bits/bytes sent on the wire of course.
在这一天结束时,如果你看一个字符串,它本身就是一个字节数组,所以第2层协议之间的区别应该线缆上正在发送的实际数据休息。换句话说,在初始数据(JPG文件)是如何连接codeD被发送之前。
at the end of the day if you look at a string it is itself an array of bytes so the distinction between the 2 protocols should rest on what actual data is being sent on the wire. in other words, on how the initial data (jpg file) is encoded before being sent.
任何评析的AP precited,我想获得的东西在这里的本质。
any coments are apprecited, I am trying to get to the essence of things here.
致敬!
推荐答案
二进制协议与文字协议是不是真的如何二进制的blob都设有codeD。所不同的是该协议确实是否是围绕的数据结构或周围的文本字符串定向。让我举一个例子:HTTP。 HTTP是一种文本协议,即使当它发送JPEG图像,它只是将原始字节,而不是它们的文本编码。
Binary protocol versus text protocol isn't really about how binary blobs are encoded. The difference is really whether the protocol is oriented around data structures or around text strings. Let me give an example: HTTP. HTTP is a text protocol, even though when it sends a jpeg image, it just sends the raw bytes, not a text encoding of them.
但是,是什么让一个HTTP协议的文本就是交换的获得的JPG格式如下:
But what makes HTTP a text protocol is that the exchange to get the jpg looks like this:
请求:
GET /files/image.jpg HTTP/1.0
Connection: Keep-Alive
User-Agent: Mozilla/4.01 [en] (Win95; I)
Host: hal.etc.com.au
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
Accept-Language: en
Accept-Charset: iso-8859-1,*,utf-8
响应:
HTTP/1.1 200 OK
Date: Mon, 19 Jan 1998 03:52:51 GMT
Server: Apache/1.2.4
Last-Modified: Wed, 08 Oct 1997 04:15:24 GMT
ETag: "61a85-17c3-343b08dc"
Content-Length: 60830
Accept-Ranges: bytes
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: image/jpeg
<binary data goes here>
请注意,这可能很容易被包装更加紧密地成结构会看(C语言)像
Note that this could very easily have been packed much more tightly into a structure that would look (in C) something like
请求:
struct request {
int requestType;
int protocolVersion;
char path[1024];
char user_agent[1024];
char host[1024];
long int accept_bitmask;
long int language_bitmask;
long int charset_bitmask;
};
响应:
struct response {
int responseType;
int protocolVersion;
time_t date;
char host[1024];
time_t modification_date;
char etag[1024];
size_t content_length;
int keepalive_timeout;
int keepalive_max;
int connection_type;
char content_type[1024];
char data[];
};
凡字段名称就不必在所有的要被发送,并且其中,例如,在的responseType
在响应结构是具有值200的int代替三个大字200。这是基于文本的协议是什么。一个被设计来传送作为文本(通常人类可读)线,而不是许多不同类型的作为结构化数据的扁平流
Where the field names would not have to be transmitted at all, and where, for example, the responseType
in the response structure is an int with the value 200 instead of three characters '2' '0' '0'. That's what a text based protocol is: one that is designed to be communicated as a flat stream of (usually human-readable) lines of text, rather than as structured data of many different types.
这篇关于二进制协议诉协议文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!