小程序无法在本地主机上创建套接字连接
我有一个java小程序,一旦加载到用户计算机上(通过网页),我希望它在正在查看它的本地计算机上创建一个服务器套接字和套接字。这是不允许的吗?
I have a java applet, which once loaded on the users machine (through the webpage), I want it to create a server socket and socket on the local machine on which it is being viewed. Is this not allowed ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java 小程序可以打开与其同源主机的
Socket
。大约十年来,他们还可以打开 ServerSocket(操作系统通常将侦听端口限制在 1024 以下)并仅接受来自同源主机的连接。此外,从 6u10 开始,crossdomain.xml
可能会放宽限制。本地主机值得注意:您的计算机向外的 IP 地址与 127.0.0.1 不同,从
file
URL 加载的代码与 127.0.0.1 的网络连接不匹配(尽管有时空字符串可以解释为 localhost;还要注意您的类路径可能指向的内容(例如.
)可能会优先于网络加载的代码加载,具体取决于您正在执行的操作,但通常不是通过浏览器)和JavaScript 仅具有同源权限,只能在下载代码的同一端口上连接到同一主机。Java applets can open
Socket
s to their same-origin host. For around a decade, they can also openServerSocket
s (the OS will typically restrict listening ports under 1024) and accept connections only from the same-origin host. In additioncrossdomain.xml
may loosen restrictions, from 6u10.Of note for localhost: your machines outward facing IP address(es) is not the same as 127.0.0.1, code loaded from
file
URLs do not match network connections to 127.0.0.1 (although sometimes the empty string can be interpreted as localhost; also note what your classpath might be pointing (say.
) may be loaded in priority to network loaded code depending upon exactly what you are doing but not normally through a browser) and JavaScript only has same-origin permissions to connect to the same host only on the same port as the code was downloaded from.如果您对小程序进行数字签名,它可以“不受限制”运行 http://显然是 download.oracle.com/javase/tutorial/deployment/applet/security.html (与 java webstart 相同)
if you digitally sign your applet, it can run "unrestricted" http://download.oracle.com/javase/tutorial/deployment/applet/security.html apparently (same with java webstart)