possible web protocols in javascript

2019-03-29 03:28发布

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条回答
Luminary・发光体
2楼-- · 2019-03-29 04:15

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.

查看更多
登录 后发表回答