JS / HTML5 WebSocket:无需HTTP调用即可连接 [英] JS/HTML5 WebSocket: Connect without HTTP call

查看:180
本文介绍了JS / HTML5 WebSocket:无需HTTP调用即可连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我刚刚尝试了HTML 5中的新WebSocket类,并且对它们的存在感到非常兴奋;然而,我没有看到它们比AJAX更有价值,看到它们仍然如何启动HTTP调用,而不像传统套接字那样。这就是为什么我在这里问。



有没有一种方法与HTML 5的 WebSocket 类连接到一个监听套接字不发送HTTP数据?目前使用TCP / IP构建器,它显示了我不想要的所有这些头文件(因为我想连接到POP3 / IMAP服务器,而不需要Flash桥或Comet等)。



听取连接...已连接
GET / HTTP / 1.1
升级:WebSocket
连接:升级
主机:localhost:666
原产地:null
Sec- WebSocket-Key1:2 987_390VNw60yi9
Sec-WebSocket-Key2:〜196 Y p 5 P67 428?


解决方案

一旦连接建立,你就拥有一个真正的套接字。但你说得对,它需要特殊的服务器支持。所以它不会让你连接到一个未修改的POP或IMAP服务器。他们选择了这种设计(升级机制),所以你可以很容易地拥有一台服务器,可以监听WebSocket连接以及真正的HTTP请求。



与AJAX和COMET的区别仍然很大。您可以使用WebSockets在服务器和客户端之间进行真正的全双工通信。以前的浏览器API还没有提供,迫使人们使用各种解决方法(例如重复的AJAX请求,COMET的永久框架等)。

Alright so I just tried out the new WebSocket class in HTML 5, and was pretty excited they exist; however, I fail to see how they are much more rewarding than AJAX seeing as how they still initiate an HTTP call and are not like conventional sockets. That's why I'm asking here.

Is there a way with HTML 5's WebSocket class to connect to a listening socket without sending HTTP data? Currently with TCP/IP builder it's showing all this header crap that I don't want (since I want to connect to POP3/IMAP servers without things like Flash bridges or Comet).

Possible?

Output from connection:

Listening for connections...Connected
GET / HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: localhost:666
Origin: null
Sec-WebSocket-Key1: 2 987_390VNw60yi9
Sec-WebSocket-Key2: ~196  Y p  5    P67 428  ?

解决方案

No. Once the connection is established you have a true socket. But you're right that it requires special server support. So it won't let you connect to an unmodified POP or IMAP server.

They chose that design (the Upgrade mechanism) so you could easily have a server that listened for WebSocket connections as well as true HTTP requests.

There is still a big distinction from AJAX and COMET. You can use WebSockets to have true full-duplex communication between server and client. Previous browser APIs haven't provided that, forcing people to use various work-arounds (such as repeated AJAX requests, COMET's forever frame, and others).

这篇关于JS / HTML5 WebSocket:无需HTTP调用即可连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆