Using Javascript to connect with server using protocol other than HTTP
Can Javascript be used to connect with a server 开发者_JAVA技巧with a protocol other than HTTP or FILE? Ideally, I would like to connect to an SMTP server using Javascript.
Not possible due to security constraints in the browser. Can be done in flash or java as far as I know. The upcoming WebSockets won't help you either.
Your best option is probably to call a script on your server which makes the socket connections to the final destination, i.e the SMTP server and then passes data back to the client over HTTP.
You do not have socket access with browser-integrated JavaScript, it would violate the sandbox security model. So no, no SMTP, or any other protocol. Even file://
should be rather difficult.
Server based JavaScript like node.js can do things like this.
Accessing e.g. SMTP via the browser is usually done through a proxy script that runs on the server and speaks HTTP to the client.
精彩评论