java小程序报SocketException或ConnectException但连接正常
我对 java applet 编程有点陌生,正在维护别人的 applet。签名的小程序会录制一些语音,然后上传文件。在上传过程中,我们有时会遇到以下异常之一(SocketException、ConnectException,甚至 UnknownHostException)。我们捕获它们,然后通过小程序的 Javascript 调用来报告它们。 javascript 调用运行良好,对我来说这表明连接正常。为什么小程序无法打开套接字或无法连接,但浏览器连接没有问题?
澄清:我所说的“连接正常”是指网络和服务器都很好,所以我不确定为什么小程序无法建立连接。
该小程序已签名并且具有网络访问权限。这种情况偶尔会发生。
谢谢
I'm somewhat new to java applet programming and am maintaining someone else's applet. The signed applet records some voice and then uploads the file. In the upload, we sometimes get one of these exceptions(SocketException, ConnectException, even UnknownHostException). We trap them, and then report them via a Javascript call from the applet. The javascript call runs fine, which to me indicates that the connection is OK. How can it be that the applet can't open a socket or can't connect but there are no issues w/ the browser connecting?
Clarification: What I meant by "connection is OK" is that the network and server are both fine, so I'm not sure why the applet can't establish the connection.
The applet is signed and does have network access. This happens very occasionally.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JavaScript 在浏览器中运行,如果与服务器交互,它会使用自己的连接。所以这无关紧要。如果小程序收到 ConnectException,则没有连接即可,如果您收到除 SocketTimeoutException 之外的任何 IOException,则连接已断开,未好吧,没有两种方法可以解决这个问题,除了关闭套接字并重新启动之外,您无能为力。
Javascript runs in the browser and it uses a connection of its own if it engages with the server. So that's irrelevant. If the applet got a ConnectException there is no connection to be OK, and if you get any IOException other than SocketTimeoutException the connection is hosed and not OK, no two ways about it, and nothing you can do except close the socket and start again.
如果没有更多信息,很难判断这里的具体问题是什么。
如果这种情况真的只是偶尔发生,并且在下一次调用(来自 JavaScript)中它工作正常,那么尝试两次来建立连接可能会有所帮助。
因此,对于更多信息,如果您能说明您正在使用哪种连接以及如何使用,将会非常有帮助。
Without more information its hard to tell what the specific problem is here.
If that really only happens very occasionally and in the next call (that from JavaScript) it works fine, it could help to just try it twice to establish the connection.
So, for further information it would be really helpful if you would state what kind of connection you are using and how.