possible web protocols in javascript

蹲街弑〆低调 提交于 2020-01-01 05:04:11

问题


What are the alternatives to HTTP (per XMLHttpRequest) when establishing a server connection in JavaScript? The only one I know is the WebSocket protocol (per WebSocket). Their corresponding secure variants https and wss included.

Would it be possible to choose an arbitrary protocol with JavaScript? How do you communicate with NTP, IMAP, UDP etc. -services for example in Node.js?


回答1:


From Node.js, you can do pretty much anything. E.g. UDP is directly supported (dgram module which is shipped with node.js), and npm has a plethora of third-party modules for many other protocols, such as SMTP, IMAP, FTP and XMPP; see https://github.com/joyent/node/wiki/Modules for one list. And if you can't find a ready made module for your favorite protocol, you can implement one yourself.

Now when it comes to browsers, you are much more limited. Those you listed are all I know (browser plugins excluded, of course). So you'd need to connect to a proxy server with HTTP(S) or ws(s) and do the actual protocol stuff from there.



来源:https://stackoverflow.com/questions/10902256/possible-web-protocols-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!