我正在尝试实施最新的websocket规范。但是,在成功握手后,我无法完成取消屏蔽步骤。
我收到以下网络套接字框架:
<<129,254,1,120,37,93,40,60,25,63,71,88,92,125,80,81,73,
51,91,1,2,53,92,72,85,103,7,19,79,60,74,94,64,47,6,83,
87,58,7,76,87,50,92,83,70,50,68,19,77,41,92,76,71,52,
70,88,2,125,90,85,65,96,15,14,20,107,31,14,28,100,27,9,
17,122,8,72,74,96,15,86,68,37,68,18,76,48,15,28,93,48,
68,6,73,60,70,91,24,122,77,82,2,125,80,81,85,45,18,74,
64,47,91,85,74,51,21,27,20,115,24,27,5,37,69,80,75,46,
18,68,72,45,88,1,2,40,90,82,31,37,69,76,85,103,80,94,
74,46,64,27,5,60,75,87,24,122,25,27,5,47,71,73,81,56,
21,27,93,48,88,76,31,57,77,74,11,55,73,68,73,115,65,81,
31,104,26,14,23,122,8,75,68,52,92,1,2,110,24,27,5,53,
71,80,65,96,15,13,2,125,75,83,75,41,77,82,81,96,15,72,
64,37,92,19,93,48,68,7,5,62,64,93,87,46,77,72,24,40,92,
90,8,101,15,28,83,56,90,1,2,108,6,13,21,122,8,82,64,42,
67,89,92,96,15,93,19,56,28,8,65,101,31,94,16,105,28,10,
20,56,30,14,65,56,27,93,71,106,16,11,17,63,25,4,17,57,
73,89,17,59,29,88,29,106,24,27,5,46,65,72,64,54,77,69,
24,122,66,93,93,49,5,12,8,109,15,28,76,59,90,93,72,56,
76,1,2,41,90,73,64,122,8,89,85,50,75,84,24,122,25,15,
23,105,25,5,19,106,26,14,20,111,25,27,5,53,77,85,66,53,
92,1,2,110,26,13,2,125,95,85,65,41,64,1,2,108,27,10,19,
122,7,2>>
根据此处定义的基本框架协议(http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17#section-5.2),我有:
fin:1, rsv:0, opcode:1, mask:1, length:126
屏蔽应用程序+有效负载数据出现:
<<87,58,7,76,87,50,92,83,70,50,68,19,77,41,92,76,71,52,70,88,2,125,90,85,65,96,
15,14,20,107,31,14,28,100,27,9,17,122,8,72,74,96,15,86,68,37,68,18,76,48,15,
28,93,48,68,6,73,60,70,91,24,122,77,82,2,125,80,81,85,45,18,74,64,47,91,85,
74,51,21,27,20,115,24,27,5,37,69,80,75,46,18,68,72,45,88,1,2,40,90,82,31,37,
69,76,85,103,80,94,74,46,64,27,5,60,75,87,24,122,25,27,5,47,71,73,81,56,21,
27,93,48,88,76,31,57,77,74,11,55,73,68,73,115,65,81,31,104,26,14,23,122,8,75,
68,52,92,1,2,110,24,27,5,53,71,80,65,96,15,13,2,125,75,83,75,41,77,82,81,96,
15,72,64,37,92,19,93,48,68,7,5,62,64,93,87,46,77,72,24,40,92,90,8,101,15,28,
83,56,90,1,2,108,6,13,21,122,8,82,64,42,67,89,92,96,15,93,19,56,28,8,65,101,
31,94,16,105,28,10,20,56,30,14,65,56,27,93,71,106,16,11,17,63,25,4,17,57,73,
89,17,59,29,88,29,106,24,27,5,46,65,72,64,54,77,69,24,122,66,93,93,49,5,12,8,
109,15,28,76,59,90,93,72,56,76,1,2,41,90,73,64,122,8,89,85,50,75,84,24,122,
25,15,23,105,25,5,19,106,26,14,20,111,25,27,5,53,77,85,66,53,92,1,2,110,26,
13,2,125,95,85,65,41,64,1,2,108,27,10,19,122,7,2>>
虽然32位屏蔽密钥是:
<<37,93,40,60,25,63,71,88,92,125,80,81,73,51,91,1,2,53,92,72,85,103,7,19,79,60,
74,94,64,47,6,83>>
根据http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17#section-5.2:
j = i MOD 4
transformed-octet-i = original-octet-i XOR masking-key-octet-j
然而,我似乎没有从客户端发送我的原始八位字节,这基本上是一个xml数据包。任何方向,更正,建议都非常感谢。
答案 0 :(得分:1)
我认为你错误地阅读了协议规范的数据框架部分。
您对第一个字节(129)的解释是正确的 - fin +操作码1 - 文本消息的最终(和第一个)片段。
下一个字节(254)意味着消息的主体被屏蔽,后面的2个字节提供它的长度(126或127的长度意味着更长的消息,其长度不能用7位表示.126表示以下2个字节保持长度; 127表示其后面的4个字节)。
以下2个字节-1,120-表示消息长度为376字节。
以下4个字节--37,93,40,60 - 是你的面具。
剩下的数据是你的信息,应该在你写的时候进行转换,给出信息
&amp; ltbody xmlns ='http://jabber.org/protocol/httpbind' rid ='2167299354'to ='jaxl.im'xml:lang ='en'xmpp:version ='1.0'xmlns:xmpp ='urn:xmpp:xbosh'ack ='1'route ='xmpp:dev.jaxl.im:5222'wait ='30'hold ='1'content ='text / xml; charset = utf-8'ver ='1.1 0'newkey ='a6e44d87b54461e62de3ab7874b184dae4f5d870'sitekey ='jaxl-0-0'iframed ='true'epoch ='1324196722121'height ='321'width ='1366'/&gt;