简体   繁体   English

Java applet可以充当服务器吗?

[英]Can a Java applet function as a server?

Is it possible to write a Java applet that can be a server on the client machine within the client's local network? 是否可以编写一个Java小程序,使其成为客户端本地网络中客户端计算机上的服务器?

To be more specific, what I am looking to do is tunnel non-web traffic over the web. 更具体地说,我要做的是通过Web传输非Web流量。 The sender would send to the applet, which would then forward the received data back to the server. 发送者将发送到applet,然后applet将接收到的数据转发回服务器。

Is this sort of thing possible? 这种事情可能吗? What are the restrictions that might get in the way? 可能会有什么限制?

Note: I know that the applet can connect back to the server, that isn't an issue. 注意:我知道applet可以连接回服务器,这不是问题。 The issue is whether or not an applet can listen for a connection / data on a local, client-side port. 问题是applet是否可以在本地客户端端口上侦听连接/数据。

An unsigned applet can only connect the host they come from. 未签名的小程序只能连接它们来自的主机。

A signed applet can do any connection you want and can listen on tcp-ip ports. 签名的小程序可以进行任何所需的连接,并且可以侦听tcp-ip端口。

Source : http://docs.oracle.com/javase/tutorial/deployment/applet/security.html 来源: http : //docs.oracle.com/javase/tutorial/deployment/applet/security.html

Server does not connect to anywhere. 服务器未连接到任何地方。 Server opens server socket and is listening. 服务器打开服务器套接字并正在侦听。

In past as far as I remember the server socket was restricted in MSIE and was permitted in Netscape (do you remember such browser?) :) 在过去,据我所知,服务器套接字在MSIE中受到限制,而在Netscape中是允许的(您还记得这种浏览器吗?):)

I personally have not been writing applets for the last 10 years, so I have no idea what happens now with currently existing browsers, but it is very easy to check. 我个人过去十年来一直没有编写applet,所以我不知道当前现有的浏览器现在会发生什么,但是非常容易检查。 Just write the shortest applet you can and put code new ServerSocket(1234).accept(); 只需编写最短的applet,然后将代码放入new ServerSocket(1234).accept(); into its init() or start() method. 放入其init()start()方法中。 If no exception was thrown you can write applet that functions as a server. 如果未引发异常,则可以编写充当服务器的小程序。 Otherwise you cannot. 否则,您将无法。

Just try it with all available browsers. 只需尝试使用所有可用的浏览器即可。 20 minutes work and you are done. 20分钟的工作就可以完成。 Good luck. 祝好运。 I'd will be glad to know about the results. 我很高兴知道结果。

Generally, it cannot. 通常,它不能。

One reason why is that applets tend to be ran within security constrained environments, which means that they are denied the ability to open server sockets. 原因之一是小程序倾向于在受安全约束的环境中运行,这意味着它们无法打开服务器套接字。

There are ways around such a restriction, basically you can specify a special security policy for the applet, or run it in a special unconstrained container; 有许多种方法可以解决这种限制,基本上,您可以为applet指定特殊的安全策略,或在不受限制的特殊容器中运行它。 but why bother when you can just port the contents of your application into a standard servlet, or even a stand-alone server? 但是,为什么只将应用程序的内容移植到标准servlet甚至是独立服务器中时又何必呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM